Live pig dynamic weighing method

By using a channel-type dynamic weighing platform and the CLANet network model, the problems of stress response and high measurement difficulty during pig weighing were solved, achieving high-precision prediction of pig weight, reducing labor intensity and improving measurement efficiency.

CN121933104APending Publication Date: 2026-04-28ZHEJIANG FORESTRY UNIVERSITY +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ZHEJIANG FORESTRY UNIVERSITY
Filing Date
2025-12-05
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing methods for weighing pigs are labor-intensive, difficult to measure, and inefficient. Furthermore, static weighing methods can easily cause stress in pigs, affecting measurement accuracy and health welfare.

Method used

By using a channel-type dynamic weighing platform combined with the CLANet network model, dynamic temporal features are extracted through the Feature-CNN module, the BiLSTM module captures the dependencies between different time periods, and the MHSA module captures the global temporal correlation, thus enabling the prediction of pig weight.

Benefits of technology

It reduced the stress response during the pig weighing process, improved measurement accuracy and robustness, and achieved high-precision pig weight prediction with a MAE of 0.99 kg, an RMSE of 1.51 kg, and a MAPE of 1.19%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121933104A_ABST
    Figure CN121933104A_ABST
Patent Text Reader

Abstract

The invention discloses a live pig dynamic weighing method, which comprises the following steps of: constructing a channel type dynamic weighing platform to acquire an original dynamic pressure signal; the method comprises the following steps of: constructing a CLANet network model comprising a Feat-CNN module, a BiLSTM module and an MHSA module; the feature matrix is input into the BiLSTM module to capture a front-back dependency relationship; the MHSA module performs multi-subspace parallel attention calculation, captures global time correlation and key feature weight distribution, and finally obtains the output of the MHSA module through splicing and linear mapping; the output of the MHSA module is processed by the two full connection layers and then mapped into a live pig weight prediction value. The method has the advantages that 0.99 kg of MAE, 1.51 kg of RMSE, 0.99 R2 and 1.19% of MAPE are obtained, hidden information contained in effective information is revealed and quantified by analyzing and processing features in dynamic weighing signals, and dynamic weighing errors are effectively reduced by extracting local features through the CNN module and capturing long time sequence dependence through the BiLSTM module.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of dynamic weighing of pigs, and more particularly to a method for dynamic weighing of pigs. Background Technology

[0002] The Food and Agriculture Organization of the United Nations predicts that global meat consumption will increase by 47.9 million tons by 2035, with pork being the third largest contributor to total meat consumption. Globally, pork slaughter is projected to reach 130 million tons. Body weight is a key indicator of pig growth and is widely used to determine feed conversion ratios, assess health status, predict optimal market dates, and optimize production plans for each batch of pigs. With increasing global demand for pork, efficient and accurate pig weight measurement is crucial for meeting market demand and ensuring farm sustainability. However, as pig farms grow in size, pig weight measurement becomes a labor-intensive task, characterized by its difficulty and low efficiency. Summary of the Invention

[0003] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method for measuring the weight of pigs in motion.

[0004] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a dynamic weighing method for pigs, comprising the following steps: constructing a channel-type dynamic weighing platform to collect raw dynamic pressure signals; constructing a CLANet network model including a Feature-CNN module, a BiLSTM module, and an MHSA module; in the Feature-CNN module, a CNN module is used to extract dynamic temporal features from the time series, while an FCN module is used to linearly map the selected highly correlated static scalar features to a high-dimensional feature space; the dynamic temporal features extracted by the CNN module and the static features encoded by the FCN module are fused to obtain a feature matrix; the feature matrix is ​​input into the BiLSTM module to capture the dependencies between time series; the MHSA module performs multi-subspace parallel attention calculation to capture global temporal correlation and key feature weight distribution, and finally obtains the output of the MHSA module through concatenation and linear mapping; the output of the MHSA module is processed by two fully connected layers and mapped to a predicted pig weight value.

[0005] Preferably, the highly correlated static scalar features are screened using the Pearson correlation coefficient, and a correlation analysis is performed between each feature and the true weight value. The specific formula is as follows.

[0006]

[0007] Where X is the eigenvalue, Y is the true body weight, and P is the calculated Pearson correlation coefficient, which is used to measure the degree of linear correlation between two variables and has a value range of [-1, 1].

[0008] Preferably, the CNN module extracts dynamic temporal features by the following steps: first, the original dynamic pressure signal is normalized; then, a one-dimensional convolutional layer is used to capture short-term dependency patterns between adjacent time segments of the dynamic pressure signal; the nonlinear expression capability of the model is introduced through the nonlinear activation function ReLU, and the feature map is downsampled by the max pooling layer, while retaining the most representative local signal features.

[0009] Preferably, the FCN module includes the following feature extraction steps: the filtered highly correlated static scalar features are used as input; the input highly correlated static scalar features are mapped to a high-dimensional feature space through a linear transformation using a fully connected neural network; batch normalization and ReLU activation function are used to improve the stability of the numerical values ​​and the feature representation ability; the static scalar features are extended to the temporal dimension through the Unsqueeze function and Repeat function; and finally, the feature matrix is ​​transposed.

[0010] Preferably, the feature fusion includes aligning and expanding the temporal features extracted by the CNN module and the scalar features processed by the FCN module in the feature dimension, and then fusing them by element-wise concatenation.

[0011] Preferably, the BiLSTM module includes the following steps: adding an LSTM layer for transmitting information in reverse chronological order; the initial layer is configured to process the input in normal chronological order, and subsequent layers are configured to process the input in reverse chronological order; the two LSTM layers share the same input, but each LSTM layer operates independently, only in opposite directions of information propagation; the final output is obtained by splicing the forward and reverse hidden states.

[0012] Preferably, the internal structure of the LSTM layer includes an input gate, a forget gate, and an output gate. The retention, forgetting, and output of information are controlled by the Sigmoid function and the Tanh function to achieve dynamic memory updates for long-range dependencies.

[0013] Preferably, the MHSA module includes the following steps: the output of the BiLSTM module is mapped to query Q, key K, and value V vectors respectively; then, the correlation weight between any two positions in the sequence is calculated through single-head scaled dot product attention; the MHSA module parallelizes the calculation process of single-head scaled dot product attention into multiple subspaces, each subspace captures different dependency patterns, and the output of the attention mechanism is obtained by concatenation and linear mapping; after the output is processed by two fully connected layers, it is mapped to a single-value prediction result of pig weight.

[0014] Preferably, the calculation process of the single-head scaled dot product attention includes the following steps: first, performing a vector dot product; then, scaling the dot product result and optionally performing a masking operation; next, normalizing using the Softmax function; and finally, performing a weighted summation of the weighted results to generate a sequence representation with enhanced contextual information.

[0015] Preferably, the channel-type dynamic weighing platform includes uphill and downhill step pads, a pressure sensor, a dynamic weighing platform, a hub, a force transmitter, a computer, and railings; the uphill and downhill step pads are used for pigs to move up and down the dynamic weighing platform; the pressure sensor is used to collect pressure data of pigs during free walking; the force transmitter is used to amplify, filter, and perform analog-to-digital conversion on the weak voltage signal output by the pressure sensor; and the computer is used for data recording and analysis.

[0016] The beneficial effects of this invention are: achieving a MAE of 0.99 kg, an RMSE of 1.51 kg, and a R... 2 With a MAPE of 1.19%, the system analyzes and processes the features in the dynamic weighing signal, reveals and quantifies the hidden information contained in the effective information, and effectively reduces the dynamic weighing error by extracting local features through the CNN module and capturing long-term time dependencies through the BiLSTM module. Attached Figure Description

[0017] Figure 1 This is a flowchart illustrating the dynamic weighing method for live pigs described in this invention.

[0018] Figure 2 This is a schematic diagram of the frame structure of the channel-type dynamic weighing platform described in this invention.

[0019] Figure 3 This is a physical schematic diagram of the channel-type dynamic weighing platform described in this invention.

[0020] Figure 4 This is a schematic diagram of the experimental pigsty floor plan described in this invention.

[0021] Figure 5 This is a schematic diagram of the network structure of the CLANet network model described in this invention.

[0022] Figure 6 This is a schematic diagram of the structure of the Feat-CNN module described in this invention.

[0023] Figure 7 This is a schematic diagram of the structure of the BiLSTM module and MHSA module described in this invention.

[0024] Figure 8 This is a schematic diagram of the pressure data of a pig normally walking across the weighing platform as described in this invention.

[0025] Figure 9 This is a schematic diagram of the pressure data showing that the pig hesitated after being placed on the weighing platform according to the present invention.

[0026] Figure 10 This is a schematic diagram of the pressure data of a pig's foot falling off the weighing platform according to the present invention.

[0027] Figure 11 This is a schematic diagram of the pressure data of a pig running rapidly across a weighing platform, as described in this invention.

[0028] Figure 12 This is a schematic diagram of the signal after using SG filtering as described in this invention.

[0029] Figure 13 This is a schematic diagram of the signal after zero-phase filtering as described in this invention.

[0030] Figure 14 This is a feature correlation heatmap of the top ten features selected according to the present invention.

[0031] Figure 15 This is a schematic diagram of the prediction structure of the CLANet network model described in this invention.

[0032] Figure 16 This is the attention heatmap of the model after introducing the attention mechanism as described in this invention. Detailed Implementation

[0033] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. The described embodiments are some, but not all, of the embodiments of the present invention.

[0034] Example 1

[0035] Traditional weighing methods often involve confining pigs to narrow cages for measurement, which can easily lead to severe stress in the pigs, potentially causing illness or even death, negatively impacting their health and welfare. Due to their considerable weight, even slight movements on the scale during weighing can cause significant fluctuations in weight, making it difficult to obtain accurate readings. Dynamic weighing systems offer a novel, non-invasive method for weight measurement, significantly reducing stress on pigs during the weighing process and enabling precise weight acquisition, thus driving the automation and intelligentization of livestock farming.

[0036] Reference Figure 1 As illustrated, in order to improve animal welfare during pig weight measurement and enhance the accuracy of pig weight measurement during movement, this application designs a novel dynamic weighing method based on a pressure sensor array, namely a dynamic weighing method for pigs, which specifically includes the following steps.

[0037] S1: Construct a channel-type dynamic weighing platform to collect raw dynamic pressure signals;

[0038] S2: Construct a CLANet network model that includes a Feat-CNN module, a BiLSTM module, and an MHSA module;

[0039] S3: In the Feature-CNN module, the CNN module is used to extract dynamic temporal features from the time series, while the FCN module is used to linearly map the filtered highly correlated static scalar features to a high-dimensional feature space. The dynamic temporal features extracted by the CNN module and the static features encoded by the FCN module are fused to obtain the feature matrix.

[0040] S4: The feature matrix is ​​input into the BiLSTM module to capture the dependencies between the preceding and following parts;

[0041] S5: The MHSA module performs parallel attention computation in multiple subspaces, captures global temporal correlation and key feature weight distribution, and finally obtains the output of the MHSA module through concatenation and linear mapping.

[0042] S6: The output of the MHSA module is processed by two fully connected layers and mapped to the predicted weight of pigs.

[0043] A channel-type dynamic weighing platform was constructed using a pressure sensor array to collect data. Simultaneously, a pig weight prediction model (CLANet network model) was proposed based on the characteristics of pig movement. The CNN module of this model is used to capture local temporal dependencies and short-term dynamic patterns, while the FCN module linearly maps the selected highly correlated static scalar features to a high-dimensional feature space. Subsequently, an early fusion strategy is used to achieve complementary enhancement between multimodal features in the feature fusion layer, learning richer and more robust features from the multimodal feature space. The fused features are used to establish long-term and short-term dependencies through the BiLSTM module, and the global temporal correlation and key feature weight distribution are captured through the multi-head self-attention mechanism (MHSA module).

[0044] Dynamic pressure signals of pigs are collected using a weighing platform placed along their walking path, and then highly correlated features are selected using Pearson correlation coefficients. A pig weight prediction model (CLANet network model) is constructed using CNN, BILSTM, MHSA modules, and highly correlated features to achieve high-precision weight prediction of pigs under movement conditions. This approach aims to: 1) reduce harm to pigs during weight measurement and improve their welfare; and 2) extract weight data using two feature extraction methods and perform multimodal feature fusion modeling to achieve high-precision weight measurement of pigs under different movement conditions, thus improving the robustness of the measurement.

[0045] Furthermore, in step S1:

[0046] Traditional pig weighing methods typically employ static weighing, requiring the pig to remain stationary on the weighing platform until the weighing signal stabilizes before reading its weight. Restraint, herding, or unfamiliar environments during the weighing process can easily trigger stress responses in pigs, leading to abnormal behavior, increased heart rate, and even affecting their feed intake and growth. This stress response not only affects the accuracy of the weighing results but also impacts the pigs' health and welfare. To address these issues, this application designs a novel dynamic weighing system (i.e., a channel-type dynamic weighing platform) that enables unrestrained dynamic weight measurement of pigs while they are freely walking.

[0047] Reference Figure 2-3The system, as illustrated, includes ramp mats 1, pressure sensors 2, a dynamic weighing platform 3, a hub 4, a force transmitter 5, a computer 6, and railings 7. The experimental subjects selected in this embodiment are three-way crossbred fattening pigs, with an average weight range of 60–150 kg, an average body length of approximately 100 cm, and a body width of approximately 35 cm. To comprehensively collect dynamic pressure data of the pigs while they are freely walking, this embodiment designed and constructed a dynamic weighing platform with a total length of 150 cm and a width of 70 cm. To facilitate the pigs' movement on and off the platform, ramp mats with a base length of 38 cm and a height of 15 cm were installed on both sides of the weighing platform. Furthermore, to guide the pigs' movement, railings 7 with a length of 200 cm and a height of 120 cm were installed on both sides of the weighing platform. A 200 cm × 70 cm anti-slip mat was laid on the dynamic weighing platform, which not only reduces slippage during the pigs' walking but also prevents pig manure from falling onto the weighing platform and causing inaccurate data collection. Before each experiment, the anti-slip mat was cleaned and the dynamic weighing platform 3 was zero-point calibrated. Considering that pigs have a strong sense of curiosity and are sensitive to environmental changes, in order to avoid sudden changes in the passage environment from interfering with their natural walking state, the dynamic weighing equipment was placed in the passage several days in advance before the experiment, so that the pigs could fully adapt to the experimental environment.

[0048] In this embodiment, the dynamic weighing platform 3 is a planar structure with pressure sensors 2 installed at each of its four corners to collect pressure data from the pigs during their free movement. The selected pressure sensor 2 has a rated range of 500 kg and an accuracy class of C3. This sensor is a piezoresistive pressure sensor, and its working principle is based on the resistance strain effect. That is, when the sensing element undergoes a small deformation under force, its resistance value changes accordingly, resulting in a change in output voltage that is linearly related to the applied load. To achieve high-precision measurement of the pressure signal, the four sensors are connected using a Wheatstone bridge to convert the weak resistance change caused by pressure into a measurable voltage signal. The voltage signals from the four sensors are integrated by a four-in-one signal hub 4 to ensure multi-point synchronous acquisition while reducing overall error. The signal is then processed by a force transmitter 5, which has a built-in digital filtering module and a 24-bit high-precision A / D converter, capable of amplifying, filtering, and converting the weak voltage signal output by the sensors. The signal processed by the transmitter is encapsulated into a digital signal conforming to the MODBUS RTU communication protocol format and transmitted to computer 6 via a wired connection for data recording and analysis. Considering the uncertainty of power supply in the application scenario, the four pressure sensors 2 are powered by a 12V battery pack, and the force transmitter 5 is powered via a USB connection to computer 6. To achieve simultaneous serial communication with the four pressure sensors 2, parsing weighing data response messages, displaying and receiving weight values, computer 6 collects dynamic pressure data by periodically sending read commands, thereby establishing communication with the sensors.

[0049] The data acquisition system used in this embodiment is equipped with multi-segment calibration functionality. Before each experiment, the dynamic weighing platform 3 is linearly calibrated using standard weights to ensure the accuracy and stability of the system measurements. Furthermore, the data acquisition system is also equipped with a zero-point calibration function to ensure that the weight remains zero when there are no pigs on the weighing platform. Since pig hooves may bring foreign objects onto the scale during continuous experiments, to prevent these objects from affecting the collected pressure data, and in cases where the weighing platform cannot be cleaned in a timely manner, this system also supports manual zero-point calibration.

[0050] After the channel-type dynamic weighing platform was constructed, data collection was conducted in July 2025 at the pig farm of Zhengxing Animal Husbandry Co., Ltd. in Hangzhou, Zhejiang Province. A total of 72 mixed-sex three-way crossbred fattening pigs (Landrace and Duroc) were used, and dynamic pressure data of 659 pigs were collected during free walking. The weight of the experimental pigs ranged from 60 to 150 kg.

[0051] Reference Figure 4As illustrated, to minimize the interference of the experimental setup on the daily production activities of the pig farm, the dynamic weighing platform was placed in the passageway between two rows of pig pens, and the original fence structure of the pigsty was used to guide the pigs' movement. The experiment divided the pigsty into three areas: the waiting area, the experimental area, and the testing completion area.

[0052] The data collection process was as follows: First, each experimental pig was assigned a unique identification number, and its corresponding information was recorded. Second, a farmer drove a pig from the inspection area to a standard pig-specific weighing scale purchased from the pig farm, obtained and recorded its actual weight value, which served as a benchmark for subsequent dynamic weighing data. Then, the farmer guided the pig to the dynamic weighing platform, collecting dynamic pressure data during its free-walking state. Due to the randomness and unpredictability of pig behavior, the farmer guided the same pig to walk back and forth on the dynamic weighing platform 3 multiple times. Finally, the pigs whose data had been collected were driven to the testing completion area. Throughout the experiment, the pressure signals and related data collected by the dynamic weighing platform 3 were stored according to the pig's identification number and the number of times it walked.

[0053] Furthermore, in step S2:

[0054] Reference Figure 5 As illustrated, Convolutional Neural Networks (CNNs) are fundamental models in the field of machine learning. Their design is inspired by the local receptive field mechanism of the biological visual system, and their core function is to extract local features from time-series signals through operations such as convolution and pooling. However, limited by the size of the convolutional kernel and the network depth, CNNs struggle to establish long-distance, cross-regional feature associations. Since pigs exhibit variable behavior and large movement amplitudes during exercise, the collected pressure data varies significantly over time. Therefore, this embodiment improves upon CNNs and proposes a CLANet network model to achieve dynamic weight measurement of pigs during free walking.

[0055] First, to address the issue of variable movement during pig walking, the model extracts effective data from the original signal using two feature extraction methods and one feature fusion method. A CNN module is used to extract local dynamic features from the time series, while an FCN module is employed to linearly map the selected highly correlated static scalar features to a high-dimensional feature space. Subsequently, an early fusion strategy is used at the feature fusion layer to achieve complementary enhancement between multimodal features, learning richer and more robust features from the multimodal feature space.

[0056] Secondly, considering the potential symmetry in pigs' walking on the platform, this embodiment introduces a BiLSTM module to capture the sequential dependencies of the fused feature temporal signals, thereby improving the model's accuracy and robustness. Finally, to address the significant changes in pressure data during pig walking, a multi-head attention mechanism (MHSA module) is introduced to establish global dependencies, highlighting key time steps and resolving the issue that CNN and BiLSTM modules cannot distinguish the importance of various features.

[0057] The screening of highly correlated static scalar features in this step is as follows.

[0058] Pigs often exhibit strong exploratory behaviors while walking, such as continuous displacement, turning, or head swinging, which can lead to the collection of invalid information in the pressure data. To reduce the impact of invalid information on subsequent weight prediction results, we first use Tsfresh, a widely used feature engineering technique, to extract features from the original signal to address the problem of extracting hidden information from the original signal. Secondly, we preserve the common features of the signal and use the Pearson correlation coefficient to select the effective features.

[0059] Tsfresh (a time series feature extraction tool based on scalable hypothesis testing) extracts hundreds of features from pig weighing stress data, covering statistics, time-domain features, and frequency-domain features. It then uses statistical hypothesis testing (such as the Mann-Whitney test and Kendall's Tau test) to filter out features relevant to pig weight prediction. In this embodiment, a total of 794 time series features are extracted from the time domain, frequency domain, and statistical features. Time-domain features (such as lag characteristics and extreme value locations) focus on the dynamic changes and adjacent point relationships of pig weighing stress data, capturing the time dependence of the sequence. Frequency-domain features (such as dominant frequency and spectral centroid) describe the frequency distribution of pig gait and the degree of energy concentration in the signal. Statistical features (such as median and variance) describe the distribution pattern, central tendency, dispersion, and numerical characteristics of pig weighing stress data.

[0060] For regression tasks involving dynamic weighing of pigs, different feature selection strategies can significantly impact weight prediction results. Selecting features with weak correlation can lead to model overfitting and weaken the algorithm's generalization ability. Therefore, this embodiment selects common features of the signals and uses the Pearson correlation coefficient for feature selection. Due to the randomness of pig movement, the number of features extracted from each signal group varies. Therefore, 156 features unique to individual signals were first removed, retaining common features. Secondly, 255 features containing "NAN" values ​​were excluded. These "NAN" values ​​are caused by mathematical overflow or underflow during the calculation process. After these feature preprocessing steps, the number of features was reduced to 383. If all preprocessed features were used as model input, it would lead to slow convergence and reduced accuracy during model training. Therefore, it is necessary to quantitatively analyze the impact of the 383 features on the prediction results to determine the most suitable features as the prediction model input.

[0061] In this embodiment, the Pearson correlation coefficient is used to analyze the correlation between each feature and the true weight value. The specific formula is as follows:

[0062]

[0063] Where X is the eigenvalue, Y is the true body weight, and P is the calculated Pearson correlation coefficient. The correlation coefficient is an indicator used to measure the degree of linear correlation between two variables, ranging from 1 to -1. Generally, a correlation coefficient less than 0.4 is considered a weak correlation or no correlation.

[0064] Furthermore, in step S3:

[0065] Reference Figure 6 As illustrated, to address the problem of invalid information generated by the variable movement of pigs during walking, this step proposes a Feature-CNN network for feature extraction and feature fusion of the original signal, so as to efficiently filter the effective features in the original signal.

[0066] The Feat-CNN network architecture mainly consists of three parts: a temporal local feature extraction module (CNN module) based on convolutional neural networks, a scalar feature extraction module (FCN module), and a fusion mechanism for the two types of features. This design aims to comprehensively utilize the dynamic changing features of time series and the global properties of static scalar features to learn richer and more robust features from a multimodal feature space.

[0067] To meet the model input format requirements, the original signal is first normalized to ensure that all signals have a length of 400 original data points. Next, a one-dimensional convolutional layer captures short-term dependency patterns between adjacent time segments of the dynamic pressure signal. Subsequently, a non-linear activation function (ReLU) is used to introduce the model's non-linear expressive power, and a max-pooling layer is combined to downsample the feature map, thereby compressing the temporal dimension, reducing computational complexity, and preserving the most representative local signal features. After processing by the CNN module, the original time series is mapped into a set of low-dimensional features rich in local temporal information, providing input for subsequent high-level temporal modeling.

[0068] In the static feature extraction module, 18 highly correlated features, filtered by Pearson correlation coefficient, are used as input. This embodiment employs a fully connected neural network to map the input scalar features to a high-dimensional feature space through linear transformation. Batch normalization and ReLU activation functions are then used to improve numerical stability and feature representation. The static scalar features are further extended to a temporal dimension using the Unsqueeze and Repeat functions, and finally, the feature matrix is ​​transposed.

[0069] In the modality fusion stage, i.e., feature fusion, the model employs an early fusion strategy, fusing the dynamic temporal features extracted by the CNN module with the static features encoded by the FCN module at the feature level. The temporal features extracted by the CNN module and the scalar embeddings processed by the FCN module are aligned and expanded along the feature dimension, and then fused element-wise. This method ensures that static features play a role at every time step, preserving not only the local continuity of the temporal pattern but also introducing global regulatory information from static features, achieving complementary enhancement between different modal features. Finally, the fused feature matrix is ​​input into the subsequent BiLSTM module to capture higher-level temporal dependencies and global patterns.

[0070] Furthermore, in step S4:

[0071] Reference Figure 7 As illustrated, classic LSTM networks only use past information when processing time-series data. However, the dynamic stress signals generated by pig walking contain rich latent temporal features. This temporal nature is particularly prominent during standard pig weighing processes. Given that the process of pigs passing through a walkway weighing platform involves a phased structure of "entering—walking on the scale—leaving," and that the weighing signals exhibit a certain degree of similarity near their peaks, this paper employs BiLSTM to simultaneously model the forward and backward temporal dependencies. This approach fully utilizes the contextual information of the passing process, thereby improving the robustness and accuracy of dynamic weight prediction.

[0072] In this embodiment, by adding an LSTM for transmitting information in reverse chronological order, the temporal correlation of dynamic stress signals can be more fully explored, thereby improving prediction accuracy. The Bidirectional Long Short-Term Memory (BiLSTM) module consists of two identical LSTM layers that share the same input. Each layer operates independently, only in opposite directions of information propagation. The initial layer is configured to process the input in normal chronological order, while subsequent layers process the input in reverse order. The internal structure of the LSTM consists of input gates, forget gates, and output gates, which regulate information retention, forgetting, and output through the Sigmoid and Tanh functions, respectively, thereby achieving long-range dependent dynamic memory updates. The final output is obtained by concatenating the forward and reverse hidden states. This bidirectional structure effectively improves the modeling capability of pig free-walking stress data.

[0073] Furthermore, in step S5:

[0074] If only BiLSTM is used to predict pig weight, then each input data point typically contributes equally to the final prediction. However, the dynamic stress signal data points generated during pig walking often exhibit significant temporal correlations, meaning that each data point is not entirely of equal importance to the final prediction. To address this issue, this embodiment introduces a multi-head self-attention mechanism (MHSA module) designed to more effectively capture the differences in importance between stress data points.

[0075] For a given time series, the attention mechanism generates an attention distribution by calculating the weight distribution at each position, which quantifies the correlation between a specific position and other positions in the sequence. The multi-head attention mechanism is an extension of the self-attention mechanism, capable of parallelizing the computation of correlations across multiple subspaces. The output of the BiLSTM module is mapped to query (Q), key (K), and value (V) vectors, respectively, and the correlation weights between any two positions in the sequence are calculated using scaled dot product attention.

[0076] The calculation process of single-head scaled dot product attention includes: first, performing a vector dot product; then, scaling the dot product result and optionally performing a masking operation; next, normalizing it using the Softmax function; and finally, performing a weighted summation of the weighted results to generate a sequence representation with enhanced contextual information.

[0077] The Multi-Head Attention (MHSA) module parallelizes the computation process into multiple subspaces, each capturing different dependency patterns. The output of the attention mechanism is obtained through concatenation and linear mapping. This output, after processing by two fully connected layers, is mapped to a single-value prediction of pig weight. By introducing the MHSA mechanism, the model can effectively assign different weights to data points at different time steps, thereby more accurately predicting weight values ​​and enhancing the model's performance in dynamic data processing.

[0078] The BiLSTM module captures the forward and backward dependencies of dynamic pressure signals through parallel computation, providing global temporal information for the model. The MHSA module, on the other hand, dynamically focuses on key time steps for weight prediction through multi-subspace parallel attention computation, enhancing the discriminative power of features and the interpretability of the model. The combination of the two enables the model to effectively extract temporal information generated by pigs during free walking at different time scales, and significantly improves the expressive power and generalization performance of pig weight prediction.

[0079] Example 2

[0080] To verify the practical effect of the dynamic weighing method for pigs proposed in this application, a comparative experiment was conducted.

[0081] The experimental environment is as follows:

[0082] In this embodiment, the PyTorch deep learning framework was used for model training. The optimizer was Adam, the batch size was set to 32, the training set to validation set ratio was 8:2, and the training epochs were 200. The initial learning rate was set to 0.001, and cosine annealing was used to achieve adaptive learning rate adjustment. The computing platform used in the experiment was configured with an Intel(R) Core(TM) i5-13600KF CPU, equipped with 32 GB of memory and an NVIDIA GeForce RTX 4060Ti GPU.

[0083] Evaluation indicators:

[0084] This embodiment uses mean absolute error (MAE), root mean square error (RMSE), mean absolute percentage error (MAPE), and coefficient of determination (R²). 2 This is used to comprehensively evaluate the model's performance. The formulas for calculating the above indicators are:

[0085] MAE=

[0086] RMSE=

[0087] MAPE=

[0088] R2 = 1

[0089] In the formula This is the actual value. This is the predicted value, where n is the number of signals acquired. It is the average of the actual values.

[0090] In this embodiment, a total of 659 pressure data points of pigs walking on the dynamic weighing platform were collected. Due to the randomness and unpredictability of pig movement, dynamic pressure data were collected for various walking states, as referenced... Figure 8-13 This section showcases some typical cases. Among them, Figure 9 This occurs when the pig's first two feet have already been on the scale, but then it steps back and then walks back again. This results in only a partial weight reading being obtained in the first half of the signal. Figure 10 The discrepancy in the collected weight values ​​was due to the fact that the pigs walked along the side of the fence, and one of their feet fell through a gap in the fence during the walk. Figure 11 The rapid running of pigs across the dynamic weighing platform causes a brief but strong spike in weight data. The diverse movement patterns of pigs present a significant challenge to developing a universal dynamic weighing method. In some studies, these specific movement patterns are considered invalid data and are therefore removed during data preprocessing. However, this embodiment retains the data from these special cases and incorporates a multi-head attention mechanism during model building, ensuring the model focuses on key information and ignores irrelevant data.

[0091] In the signal preprocessing stage, traditional dynamic weighing methods typically discard data from the time the person enters and exits the weighing platform. This embodiment also retains this data. Discarding this timeframe would lead to insufficient utilization of the overall dynamic pressure signal, thus affecting weight prediction. Therefore, the entire raw signal is input into the model for learning. Furthermore, we found that smoothing the data during preprocessing can actually cause the loss of some useful information, leading to certain deviations in the final results, such as… Figure 12 It uses SG filtering. Figure 13 This is the result after using zero-phase filtering, and... Figure 12 and Figure 13The pig in the middle signal was running rapidly across the weighing platform, causing a brief and strong signal waveform. The pig's true weight was 83.3 kg. After preprocessing the data using two different filtering methods, it was found that the maximum value of the processed data only remained around 60-70 kg, which is far from the true weight, causing distortion of the model's input data. To remove noise and interference while preserving effective information in the signal, this embodiment combines local features extracted by the CNN module with selected highly correlated scalar features to eliminate the influence of useless information on the model. Furthermore, a BiLSTM module is used to capture long-distance temporal dependencies. This combination of modules ensures reliable weight prediction even when the pig is moving rapidly.

[0092] Scalar feature extraction results:

[0093] After screening by Pearson correlation coefficient, 18 features with a value greater than 0.4 were identified. Table 1 shows the top ten feature names and their corresponding correlation coefficients. For example, "value mean n absolute max number of maxima" reflects the transitions between multiple steps or movements of the pig on the scale, helping to identify the pig's walking stage or movement pattern; the feature "valuemaximum" is crucial for capturing peak values ​​in dynamic stress, directly reflecting the pig's peak weight; "value variance" reflects the fluctuations in stress during walking, helping to capture gait changes and thus improving the accuracy of weight prediction; "value c3 lag 3" is similar to lag 1 and lag 2, helping to capture changes in the pig's movement pattern over a longer period during dynamic weighing. In summary, combining statistical features and time lag features can effectively extract the influence of different synchronicities of pigs during free walking on weight prediction, improving the accuracy and robustness of the model.

[0094] Table 1: Top ten features after screening by Pearson coefficient.

[0095] Ranking Feature Name Correlation coefficient 1 value mean n absolute max number of maxima 7 0.98 2 value absolute maximum 0.95 3 value maximum 0.95 4 value cidce normalize False 0.61 5 value variance 0.59 6 Value standard deviation 0.55 7 value c3 lag 1 0.51 8 value c3 lag 2 0.50 9 value c3 lag 3 0.50 10 value change quantiles f agg "var" isabs False qh 1.0 ql 0.42

[0096] Reference Figure 14 The illustration shows a heatmap of the feature correlations of the top ten selected features. Figure 14It can be seen that the selected features not only have a high correlation with actual body weight, but also a high correlation between features. Most features show high correlation with other features, indicating that these features can effectively capture fluctuations in dynamic stress signals and reflect changes in pig weight. However, the tenth feature has a weaker correlation with other features. This is because this feature mainly represents the amount of change in the signal at different fractions, primarily capturing deeper information about the signal's change patterns, thus exhibiting a weaker correlation with other features. However, it is still helpful in analyzing the amplitude and degree of fluctuation of the signal, and is equally important for measuring the dynamic body weight of pigs.

[0097] To verify the performance of the CLANet network model in predicting body weight, 20% of the 659 collected data points were used for testing, and the remaining data were used for model training. To prevent information from the validation set from affecting the training process, the data was normalized using only the mean and standard deviation calculated from the training set.

[0098] Reference Figure 15 This shows the prediction results of CLANet on the first fifty samples in the validation set. Compared with the collected actual weights, CLANet's MAE, RMSE, and R... 2 The MAPE values ​​were 0.99 kg, 1.51 kg, 0.99%, and 1.19%, respectively. (By...) Figure 15 As can be seen, the curves predicting body weight using CLANet largely overlap with the curves predicting actual body weight, with only minor discrepancies in a few individual samples. Figure 15 It can be seen that the error between most samples and the true value is within 1 kg, but a small number of samples, such as sample 1 and sample 29, have poor prediction results. This is because these pigs are relatively large in weight and length, resulting in a shorter time for them to walk across the dynamic weighing platform, which affects the quantity and quality of effective data, leading to a certain deviation in the final prediction results.

[0099] Based on the electrical characteristics of pressure sensor 2, the theoretical accuracy of the dynamic weighing platform 3 is ±0.334 kg. Due to the complexity of the pig farm environment, the actual weighing error may be larger. However, the model in this embodiment achieved a mean absolute error of 0.99 kg across the entire pig weight range (60-150 kg). This difference between theoretical static accuracy and dynamic measurement error is expected, and other studies using weighing sensors for livestock weighing have encountered the same problem. For example, Alawneh's research indicated a measurement error of 1.5-2.0 kg for a dairy cow walking weighing system, despite using a scale with a static accuracy of less than 1 kg. Similarly, Parsons found an error of 1.3-1.8 kg in their weighing system. Importantly, the error of the model in this embodiment is acceptable in commercial pig production; a weight estimate within ±2-3 kg is considered sufficient for management decisions such as sorting and transportation. Combining the findings of this embodiment and other studies, although the model in this study may not achieve the theoretical static accuracy, it provides a reliable measurement method applicable to real pig farm environments.

[0100] Model comparison experiment:

[0101] To verify the performance of the CLANet model in this embodiment, 18 widely used regression models were selected, and 18 features with the same input as this model were used as input for regression analysis. The comparison results are shown in Table 2.

[0102] Table 2: Comparison results with other models.

[0103] Ranking Model Name MAE / kg RMSE / kg [R 2 ]]> MAPE / % 1 This model 0.99 1.51 0.99 1.19% 2 Lasso Regression 1.51 2.22 0.97 1.86% 3 Huber Regressor 1.55 2.29 0.96 1.94% 4 Elastic Net 1.67 2.36 0.96 2.03% 5 Lasso Least Angle Regression 4.19 5.75 0.76 5.01% 6 Passive Aggressive Regressor 4.45 5.55 0.70 5.40% 7 K Neighbors Regressor 5.17 7.41 0.66 6.21% 8 Extra Trees Regressor 7.98 9.74 0.42 9.73% 9 Orthogonal Matching Pursuit 7.66 10.14 0.36 9.26% 10 Light Gradient Boosting Machine 9.41 12.13 0.12 11.30% 11 Ridge Regression 9.59 12.79 0.04 11.40% 12 Random Forest Regressor 9.90 13.18 -0.02 11.77% 13 AdaBoost Regressor 9.94 13.17 -0.02 11.83% 14 Linear Regression 9.90 13.20 -0.02 11.76% 15 Bayesian Ridge 9.90 13.20 -0.02 11.76% 16 Dummy Regressor 9.90 13.20 -0.02 11.76% 17 Gradient Boosting Regressor 9.93 13.20 -0.02 11.81% 18 Decision Tree Regressor 9.93 13.21 -0.02 11.81% 19 Least Angle Regression 906.57 1486.10 -35786.67 1090.15%

[0104] As shown in Table 2, the method proposed in this application outperforms other methods in all evaluation metrics. Compared with Lasso Regression (L1 regularized regression), the best-performing linear regression and regularization method, and Extra Trees Regressor (extreme random tree regression), the best-performing decision tree and ensemble method, CLANet reduces MAE by 34.44% and 87.59%, RMSE by 31.99% and 84.49%, respectively, and MAPE by 36.02% and 87.77%, respectively. The R² values ​​for the two models are 0.97 and 0.42, respectively. From the perspective of model interpretability, both are weaker than the method proposed in this application. Specifically, although Lasso Regression achieves relatively ideal prediction results on the validation set, its regularization compresses all coefficients, causing the coefficient estimates of important features to deviate from the true values, thereby reducing the model's prediction accuracy. When there are multiple highly correlated features, Lasso Regression often randomly selects one to retain, compressing the others to zero, resulting in unstable results. Most importantly, Lasso Regression is based on least squares loss by default, and outliers significantly amplify the sum of squared residuals. The complexity and unpredictability of pig movement generate a large number of outliers, which can lead to the model being overly biased towards outliers, reducing the overall stability of the prediction. Extra Trees Regressor has the advantages of fast training speed and strong resistance to overfitting, but due to the overly random splitting process, the fitting ability of a single tree is weak, which may lead to overfitting for the dynamic signal of predicting the weight of a single pig. Moreover, similar to the Random Forest method, Extra Trees Regressor is prone to bias towards numerical features, ultimately leading to distortion in the predicted weight.

[0105] In this embodiment, some models were found to have poor prediction performance during the experiment. For example, models ranked 12th and below all showed R... 2The case of a negative R². As the formula for R² shows, if SSE (Sum of Squared Residuals) is greater than SST (Sum of Squared Total), then R² will definitely be negative. This is because, under normal circumstances, even a poorly performing model can fit some of the data, so the normal range of R² is between 0 and 1. If the result is negative, the core reason is that the model's prediction performance is worse than predicting using the mean of the target variable. Essentially, the model completely fails to capture the patterns in the feature data and may even introduce an incorrect fitting direction. The results of the Least Angle Regression experiment were the most unexpected. This is because this model is designed for situations where the number of features is much larger than the number of samples. However, this study used 18 highly correlated features to train on 659 samples. The sheer number of features indicates that this model is unsuitable for training the data in this study. If the model's data contains highly correlated features, it will select all features simultaneously, leading to unstable coefficient estimation and affecting the final prediction results.

[0106] Ablation experiment:

[0107] To further verify the impact of each improved module on the dynamic weight prediction performance of CLANet, ablation experiments were designed by combining the BiLSTM module with different modules, and the results are shown in Table 3.

[0108] Table 3: Ablation test results.

[0109] BiLSTM CNN MHA FAETURES MAE / kg RMSE / kg <![CDATA[R 2 ]]> MAPE / % √ - - - 2.51 3.85 0.89 3.02% √ √ - - 9.56 14.97 -0.13 10.48% √ √ √ - 1.85 5.97 0.82 1.58% √ √ √ √ 0.99 1.51 0.99 1.19%

[0110] As shown in Table 3, after introducing the CNN module, the model's MAE, RMSE, and MAPE are all significantly improved compared to using BiLSTM alone, and even R... 2 The case of a negative number indicates that the model has essentially failed to learn a useful regression relationship, and the result is even worse than simple mean prediction. This is because although CNNs extract local signal features and BiLSTMs can capture long-term temporal dependencies, the model does not know the importance of these features, leading to the forgetting of important information. After introducing a multi-head attention mechanism, MAE and MAPE decreased by 26.29% and 47.68% respectively, RMSE improved by 55.06%, and R... 2 The value decreased to 0.82, indicating that the introduction of the attention mechanism allows the model to focus on which features are more important during extraction, while the weights of irrelevant features or noisy data points will approach 0, resulting in higher prediction accuracy.

[0111] Reference Figure 16The diagram illustrates the model's attention heatmap after incorporating the attention mechanism. The depth of the color represents the model's focus on a particular part of the signal. With the attention mechanism, the model is prone to significant bias in predicting extreme values, and RMSE is more sensitive to large errors because squaring amplifies large biases, leading to a slight increase in RMSE. When all three modules are introduced simultaneously, the model performance reaches its optimal level, with MAE, RMSE, and MAPE reduced by 60.56%, 60.78%, and 60.60%, respectively, compared to using only the BiLSTM module. R0 2 The accuracy reached 0.99. In summary, the improved model in this embodiment significantly improves both interpretability and prediction accuracy.

[0112] This application proposes a dynamic weighing method for pigs, using a channel-type dynamic weighing platform constructed with a pressure sensor array to collect data. A pig weight prediction model, CLANet, is proposed based on the characteristics of pig movement. The model's CNN module captures local temporal dependencies and short-term dynamic patterns; the FCN module linearly maps the selected highly correlated static scalar features to a high-dimensional feature space; subsequently, the two types of modal features are complementary and enhanced at the feature fusion layer through an early fusion strategy, learning richer and more robust features from the multimodal feature space. The fused features are modeled with long-term and short-term dependencies using a BiLSTM module, and a multi-head self-attention mechanism captures global temporal correlation and key feature weight distribution. Experimental results show that the proposed model achieves a MAE of 0.99 kg, an RMSE of 1.51 kg, and an R² of 0.99 kg on a dataset of 659 pig dynamic stress data points. 2 And 1.19% MAPE. By analyzing and processing the features in the dynamic weighing signal, the hidden information contained in the effective information is revealed and quantified. The dynamic weighing error is effectively reduced by extracting local features through the CNN module and capturing long-term time dependencies through the BiLSTM module.

[0113] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, portable hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the method according to the embodiments of the present invention.

[0114] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the scope of protection of the present invention. For those skilled in the art, other variations or modifications can be made based on the above description and ideas, and it is neither necessary nor possible to exhaustively describe all implementation methods here. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the technical solutions of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A method for dynamic weighing of live pigs, characterized in that: Includes the following steps, Construct a channel-type dynamic weighing platform to collect raw dynamic pressure signals; Construct a CLANet network model that includes a Feat-CNN module, a BiLSTM module, and an MHSA module; In the Feature-CNN module, a CNN module is used to extract dynamic temporal features from the time series, while an FCN module is used to linearly map the filtered highly correlated static scalar features to a high-dimensional feature space. The dynamic temporal features extracted by the CNN module and the static features encoded by the FCN module are then fused to obtain a feature matrix. The feature matrix is ​​input into the BiLSTM module to capture the dependencies between different parts of the graph. The MHSA module performs multi-subspace parallel attention computation, captures global temporal correlation and key feature weight distribution, and finally obtains the output of the MHSA module through concatenation and linear mapping. The output of the MHSA module is processed by two fully connected layers and mapped to the predicted weight of pigs.

2. The dynamic weighing method for pigs according to claim 1, characterized in that: The highly correlated static scalar features were selected using the Pearson correlation coefficient, and a correlation analysis was performed between each feature and the true weight value. The specific formula is as follows. Where X is the eigenvalue, Y is the true body weight, and P is the calculated Pearson correlation coefficient, which is used to measure the degree of linear correlation between two variables and has a value range of [-1, 1].

3. The dynamic weighing method for pigs according to claim 1, characterized in that: The CNN module extracts dynamic temporal features through the following steps. First, the original dynamic pressure signal is normalized. Then, a one-dimensional convolutional layer is used to capture short-term dependency patterns between adjacent time segments of the dynamic pressure signal; The nonlinear expression capability of the model is introduced by using the nonlinear activation function ReLU, and the feature map is downsampled by combining the max pooling layer, while retaining the most representative local signal features.

4. The dynamic weighing method for pigs according to claim 1, characterized in that: The FCN module includes the following feature extraction steps. The filtered highly correlated static scalar features are used as input; The highly correlated static scalar features input are mapped to a high-dimensional feature space through a linear transformation using a fully connected neural network. Batch normalization and ReLU activation function are used to improve the stability of numerical values ​​and the ability to represent features; The static scalar features are extended to the temporal dimension using the Unsqueeze and Repeat functions, and finally the feature matrix is ​​transposed.

5. The dynamic weighing method for pigs according to claim 1, characterized in that: The feature fusion includes aligning and expanding the temporal features extracted by the CNN module and the scalar features processed by the FCN module in the feature dimension, and then fusing them by element-wise concatenation.

6. The dynamic weighing method for pigs according to claim 1, characterized in that: The BiLSTM module includes the following steps. Add an LSTM layer for transmitting information in reverse chronological order; The initial layer is configured to process the input in normal chronological order, and subsequent layers are configured to process the input in reverse chronological order. The two LSTM layers share the same input, but each LSTM layer operates independently, only in opposite directions of information propagation. The final output is obtained by concatenating the forward and reverse hidden states.

7. The method for dynamic weighing of pigs according to claim 1, characterized in that: The internal structure of the LSTM layer includes an input gate, a forget gate, and an output gate. The retention, forgetting, and output of information are controlled by the Sigmoid function and the Tanh function to achieve dynamic memory updates for long-range dependencies.

8. The method for dynamic weighing of pigs according to claim 1, characterized in that: The MHSA module includes the following steps. The output of the BiLSTM module is mapped to query Q, key K, and value V vectors, respectively. Next, the correlation weights between any two positions in the sequence are calculated using single-head scaled dot product attention. The MHSA module parallelizes the computation process of single-head scaled dot product attention into multiple subspaces. Each subspace captures different dependency patterns, and the output of the attention mechanism is obtained through concatenation and linear mapping. After being processed by two fully connected layers, the output is mapped to a single-value prediction result of the pig's weight.

9. The dynamic weighing method for live pigs according to claim 8, characterized in that: The calculation process of the single-head scaling dot product attention includes the following steps: First, perform a vector dot product, then scale the dot product result, and optionally perform a masking operation; Then, normalization is performed using the Softmax function; Finally, the weighted results are summed to generate a sequence representation with enhanced contextual information.

10. The method for dynamic weighing of pigs according to claim 1, characterized in that: The channel-type dynamic weighing platform includes uphill and downhill step pads (1), pressure sensor (2), dynamic weighing platform (3), hub (4), force transmitter (5), computer (6) and railing (7). The uphill and downhill step pads (1) are used for pigs to go up and down the dynamic weighing platform (3). The pressure sensor (2) is used to collect pressure data of pigs during free walking; The force transmitter (5) is used to amplify, filter and convert the weak voltage signal output by the pressure sensor (2) into analog and digital signals. The computer (6) is used for data recording and analysis.