Cow posture recognition method based on triaxial angular velocity signal of gyroscope

By constructing features and performing unsupervised clustering from data from three-axis gyroscope sensors in cattle, combined with a multilayer perceptron model, the problem of deployment difficulties and poor adaptability of existing image recognition methods in the breeding environment is solved, and stable, low-energy posture recognition and early warning functions are achieved.

CN121542858AActive Publication Date: 2026-02-17YUNNAN ZHENTU INFORMATION TECHNOLOGY CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202610049182.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-15
Publication Date
2026-02-17
Estimated Expiration
2046-01-15

AI Technical Summary

Technical Problem

Existing image recognition-based cattle posture recognition methods are difficult to deploy in actual breeding environments, have poor environmental adaptability, are highly dependent on computing power, have high computational complexity, and have limited model generalization ability, making them difficult to adapt to complex application scenarios in different regions and under different shooting conditions.

Method used

By collecting data from three-axis gyroscope sensors inside cattle, various motion feature variables are constructed. Unsupervised clustering is then performed by combining an autoencoder with fusion contrast constraints and a Gaussian mixture model. A multilayer perceptron model is then constructed for posture recognition, achieving posture recognition without the need for an external camera system.

Benefits of technology

It achieves stable posture recognition in both captive and grazing environments, reduces computational complexity and energy consumption, improves the model's generalization ability and robustness, has strong adaptability, reduces deployment and maintenance costs, and has real-time recognition and intelligent early warning functions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121542858A_ABST
    Figure CN121542858A_ABST
Patent Text Reader

Abstract

The invention relates to a cattle posture recognition method based on triaxial angular velocity signals of a gyroscope, and belongs to the technical field of crossing of animal behavior recognition, sensor signal processing and artificial intelligence application. The method comprises the following steps: 1) data acquisition and feature construction; 2) generating an unsupervised clustering label; 3) supervising signal processing and classifier construction; and 4) attitude discrimination. According to the method, the automatic identification of the posture state of the cattle is realized by collecting the three-axis angular velocity data generated by the gyroscope sensor in the cattle and combining the means of feature extraction, unsupervised clustering, supervised classification and the like. Data dependent on the method are all from in-vivo sensor signals, and are hardly interfered by external factors such as temperature change, terrain fluctuation and breeding environment, so that the method has the remarkable advantages of stable data acquisition, low calculation overhead, flexible deployment and the like, can be widely applied to various breeding scenes such as captivity and grazing, and has wide application prospects. And the practicability and adaptability of the cattle behavior monitoring system can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the technical field of animal behavior recognition, sensor signal processing and artificial intelligence applications, and in particular relates to a method for recognizing bovine posture based on three-axis angular velocity signals from a gyroscope. Background Technology

[0002] In existing technologies, methods for identifying bovine postures mainly rely on visual perception, that is, extracting key skeletal points or external contour features from monitoring images using deep learning algorithms, and then classifying the posture using a posture discrimination model. For example, patent application CN118736486A, "A Method for Monitoring and Identifying Abnormal Behavior and Posture in Cattle," proposes a monitoring method that identifies abnormal behavior based on the coordinates of key skeletal points in monitoring images. Another example is patent application CN120071398A, "A Method and System for Extracting Joint Points and Recognizing Posture in Cattle Skeleton Based on Visual Sensing," which extracts features from video images and combines them with a Transformer model-based target detection algorithm to achieve accurate localization and posture recognition of bovine image regions.

[0003] Although existing image recognition-based cattle posture recognition methods have certain application value in captive environments, there are still many obstacles and shortcomings in actual deployment and operation.

[0004] First, such methods are highly sensitive to the quality of the image input and the integrity of the target structure. The detection accuracy of skeletal key points is easily affected by uneven lighting, background occlusion, overlapping of objects, or motion blur. In practical applications, problems such as reduced pose recognition accuracy, missed detection, or false detection of targets are likely to occur.

[0005] Secondly, due to the wide distribution of cattle, their scattered locations, and the low density of camera equipment deployment, image acquisition faces problems such as discontinuous field of view and tracking interruption. At the same time, considering the weak infrastructure in grazing environments, image acquisition equipment faces many obstacles in terms of power supply, installation, and network connection, resulting in high overall deployment and maintenance costs, which limits its application effectiveness in wide-area grazing environments.

[0006] Furthermore, this type of method involves a large number of convolution operations and multi-layer self-attention calculations in image processing and feature extraction, resulting in high overall computational complexity and placing high demands on the computing power and memory of edge computing terminals. In addition, the continuous transmission of high-resolution images and videos also puts great pressure on the bandwidth and stability of the network, thus limiting the deployment flexibility of this method in environments with limited computing power or poor network conditions.

[0007] Finally, these methods are mostly trained based on fixed perspectives and specific datasets, and they exhibit high sensitivity when factors such as camera installation location, shooting angle, or cattle breed change. The generalization ability of the model is relatively limited, making it difficult to adapt to complex application scenarios with different geographical environments, breed differences, or diverse shooting conditions. Summary of the Invention

[0008] This invention aims to provide a method for cattle posture recognition based on three-axis angular velocity signals from a gyroscope, addressing the problems of existing image recognition methods, such as difficulty in deployment in practical farming environments, poor environmental adaptability, strong computational dependence, and limited model generalization ability. This method collects three-axis angular velocity data generated by gyroscope sensors within the cattle and combines it with feature extraction, unsupervised clustering, and supervised classification to achieve automated recognition of cattle posture. Since the data relied upon in this invention comes entirely from in-vivo sensor signals, it is virtually unaffected by external factors such as temperature changes, terrain variations, and the farming environment. Therefore, it possesses significant advantages such as stable data acquisition, low computational overhead, and flexible deployment, and can be widely applied to various farming scenarios, including penning and grazing, effectively improving the practicality and adaptability of cattle behavior monitoring systems.

[0009] The present invention is implemented using the following technical solution.

[0010] A method for cattle attitude recognition based on gyroscope three-axis angular velocity signals, the method comprising the following steps:

[0011] Step 1) Data Acquisition and Feature Construction

[0012] The rotational angular velocity data of cattle in three orthogonal directions (front-back, left-right, and up-down) is obtained by using the triaxial gyroscope built into the bovine rumen sensor; feature variables are constructed based on the angular velocity data.

[0013] Step 2) Unsupervised clustering label generation

[0014] An unsupervised clustering mechanism combining a contrastive autoencoder with Gaussian mixture model (GMM) is adopted.

[0015] Step 3) Supervised signal processing and classifier construction

[0016] The feature variables are standardized using the mean and standard deviation method; the labels generated by clustering are one-hot encoded as supervision signals; a multilayer perceptron (MLP) model is constructed, and the classifier is trained by combining an early stopping mechanism. The MLP model includes at least an input layer, a hidden layer, and an output layer.

[0017] Step 4) Attitude determination

[0018] The newly acquired gyroscope three-axis angular velocity data is processed using the same feature construction and standardization methods as in the training phase, then input into the trained MLP model to output the cow's current posture category.

[0019] In step 1) of this invention, data acquisition and feature construction, the feature variables include: angular velocity modulus, which is used to characterize the combined motion amplitude of the three-axis angular velocities;

[0020] The directional amplitude ratio is calculated by introducing a stability factor to determine the relative magnitudes of the angular velocities along each axis.

[0021] Angular velocity variance is used to measure the dispersion of triaxial angular velocities.

[0022] Dominant axis identification: The dominant rotation direction is determined by comparing the absolute values ​​of the three-axis angular velocities.

[0023] Dynamic variation differential features are used to characterize the attitude change trend between consecutive time points.

[0024] Step 2) of this invention, unsupervised clustering label generation, includes:

[0025] Construct a contrastive autoencoder with an input layer dimension matching the number of feature variables. The encoder consists of two fully connected layers with activation functions and a linearly activated latent representation layer. The decoder is a symmetric inverse structure of the encoder.

[0026] Construct positive and negative sample pairs, where positive sample pairs consist of data from adjacent time points, and negative sample pairs consist of data from the current time point and random time points;

[0027] Define a weighted total loss function, which includes a reconstruction loss function and a contrastive loss function. Update the network parameters through backpropagation and use the Adam optimizer for iterative training.

[0028] Low-dimensional vectors of the latent space of the autoencoder after training are extracted, clustered using the GMM model, and the model parameters are optimized using the expectation-maximization algorithm (EM) to generate sample class labels.

[0029] This invention protects the application of the method described in identifying the posture of cattle.

[0030] A cattle attitude recognition device based on gyroscope three-axis angular velocity signals, comprising:

[0031] The data acquisition and feature construction module is used to acquire the rotational angular velocity data of cattle in three orthogonal directions (front-back, left-right, and up-down) through the triaxial gyroscope built into the bovine rumen sensor; and to construct feature variables based on the angular velocity data.

[0032] An unsupervised clustering label generation module is used for an unsupervised clustering mechanism that combines a contrastive autoencoder with a Gaussian mixture model (GMM) with fused contrastive constraints.

[0033] The supervised signal processing and classifier construction module is used to standardize the feature variables using the mean and standard deviation method; the labels generated by clustering are one-hot encoded as supervised signals; a multilayer perceptron (MLP) model is constructed and the classifier is trained using an early stopping mechanism. The MLP model includes at least an input layer, a hidden layer, and an output layer.

[0034] The attitude discrimination module is used to process newly acquired gyroscope three-axis angular velocity data according to the same feature construction and standardization method as in the training phase, input the data into the trained MLP model, and output the attitude category of the cow at the current moment.

[0035] A computer storage medium having a computer program stored thereon, wherein the computer program, when executed by a machine, implements the steps of the method described.

[0036] A computer device includes a processor, a memory, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above-described method.

[0037] A method for cattle attitude recognition based on gyroscope three-axis angular velocity signals, comprising the following steps:

[0038] Step 1: Obtain angular velocity data using the triaxial gyroscope built into the bovine rumen sensor.

[0039] Step 2: Based on the original triaxial angular velocity data gyroX, gyroY, and gyroZ, respectively, record the rotational angular velocities of the cow in the three orthogonal directions of forward / backward, left / right, and up / down; For discrete time steps, all quantities with subscript t in the text represent the value at time step t, and t-1 and t+1 represent the adjacent time steps before and after it, respectively. Based on this, the following feature variables are constructed:

[0040] 1) Angular velocity modulus (gyro_norm): This measures the combined modulus of the three-axis angular velocities at a given time point, reflecting the instantaneous motion amplitude of the cattle as a whole. The formula is defined as follows:

[0041] ;

[0042] 2) The directional amplitude ratios (gyro_xy_ratio, gyro_xz_ratio, gyro_yz_ratio) are defined by the following formula:

[0043] ;

[0044] ; ;

[0045] in This is introduced as a stabilizing factor to prevent numerical instability caused by a denominator of zero.

[0046] 3) Angular velocity variance This is used to measure the dispersion of the three-axis angular velocity at a given time point, reflecting the degree of drastic change in the cattle's posture at that time point. The formula is defined as follows:

[0047] ; ;

[0048] 4) Dominant axis identification (gyro_max_axis): This identifies the axis with the largest absolute value among the three-axis angular velocities at the current moment. It represents the dominant direction of the cow's most significant rotation at that time. The formula is defined as follows:

[0049] ;

[0050] 5) Dynamic variation differential features, used to measure the trend of posture changes in cattle over consecutive time points, are defined by the following formula:

[0051] ; ; ; ; .

[0052] Step 3: After feature construction, a contrastive autoencoder with fusion constraints is used to extract the low-dimensional latent representation of the samples. Then, unsupervised clustering is performed using a Gaussian Mixture Model (GMM) to achieve automatic generation of data labels. This includes the following key sub-steps:

[0053] Step 3.1: Define the time series format of the cattle angular velocity behavior feature sample set as follows: Where D=11 is the number of angular velocity features constructed in the previous step, and N is the number of samples; a contrastive autoencoder with input layer dimension D is constructed, and its structural expression is as follows:

[0054] In the encoder part, the model includes a fully connected layer with two ReLU activations and a latent representation layer with linear activation, as shown in the following structure:

[0055] ; ; ;

[0056] Among them, (12) is the first hidden layer containing 64 neurons, and the Dropout random deactivation mechanism is introduced to randomly block the output of some neurons with a 5% probability during training to improve the generalization ability of the model; (13) is the second hidden layer containing 32 neurons, and the Dropout mechanism is introduced. The encoder network transforms the input features into a latent representation, which is then used for subsequent behavior pattern learning. The decoder is a symmetric inverse structure of the encoder, and its output is the reconstructed feature samples. .

[0057] Step 3.2: Construct positive and negative sample pairs respectively, where the positive sample pairs are formed by adjacent time steps (z). t ,z t+1 The negative class consists of the sample and a random time (z). t ,z r The sample pairs are composed of labels, expressed as follows:

[0058] ;

[0059] Step 3.3: Define the loss function and train the model. In each training round, the gradient of the total loss function with respect to the network parameters is calculated through backpropagation. The Adam optimizer is then used to iteratively update the parameters (including weights and biases) of each layer of the autoencoder based on this gradient, thereby minimizing the loss value. The specific expression is as follows:

[0060] ; ; ;

[0061] Where m=1.0 is the contrast margin threshold, and M is the number of sample pairs used in training. i ,b i () represents the indices at both ends of the i-th sample pair. The labels are constructed in the previous step. Equation (16) is the reconstruction loss function, equation (17) is the contrastive loss function, and equation (18) is the total loss function calculated by weighting the two.

[0062] ;

[0063] in, This represents all trainable parameters of the autoencoder network in the t-th training round, including the weight matrix and bias terms of each layer; This represents the learning rate, used to control the step size for each parameter update; This represents the gradient of the loss function with respect to the parameters.

[0064] Step 3.4: After the autoencoder training is complete, extract the low-dimensional vector mapped into the latent space by the encoder network. ,in This represents the trained encoder function. Based on this, a Gaussian Mixture Model (GMM) is used to cluster the latent vector (4 classes) to extract behavioral features of cattle. The specific expression is as follows:

[0065] ;

[0066] in, Let be the mixing coefficient of the k-th Gaussian component, satisfying ,and ; Let be the mean vector of the k-th Gaussian component; Let be the covariance matrix of the k-th Gaussian component; This represents a 4-dimensional Gaussian distribution.

[0067] Next, initialize the parameters mentioned above and train the model using the Expectation-Maximization (EM) algorithm. First, calculate the value of each sample z. t The posterior probability of belonging to the k-th Gaussian component:

[0068] ;

[0069] Where K is the number of Gaussian components in the Gaussian mixture model, i.e., the set number of clusters; j is the index of the Gaussian component (cluster), used to sum all the clusters. This indicates that under the current model parameters, the sample The posterior probability generated by the k-th Gaussian component. Based on Then, update the parameters. The specific update process is as follows.

[0070] ; ; ;

[0071] The above process is repeated iteratively. After reaching the preset maximum number of iterations, for each sample z... t The component with the highest posterior probability is selected as the clustering result. To obtain the category label of the sample. The meanings of each label are as follows: 0 - Slow movement (medium to large amplitude | low volatility), 1 - Active (medium amplitude | high volatility), 2 - Violent (large amplitude | high volatility), 3 - Stagnant movement (small amplitude | low volatility).

[0072] Step 4: To ensure network convergence stability, construct feature x. ij Perform standardization processing and use the labels obtained in the previous step. One-hot encoding is performed using the following expression:

[0073] ;

[0074] in, and denoted as the mean and standard deviation of the j-th feature, respectively.

[0075] Step 5: Using the aforementioned labeling results as supervision signals, construct a cattle posture classifier based on three-axis angular velocity features. A multi-layer perceptron model is employed, combined with an early stopping mechanism to improve the model's generalization performance. This includes the following key sub-steps:

[0076] Step 5.1: Construct a feedforward neural network model (MLP) consisting of three fully connected neural networks to supervise the modeling of pose clustering results. The specific structure is as follows:

[0077] ; ; ; ; ;

[0078] In this context, equation (26) represents the first hidden layer containing 128 neurons; equation (27) normalizes the result of equation (26) and introduces the Dropout mechanism; equation (28) represents the second hidden layer containing 64 neurons; equation (29) also normalizes the structure of equation (28) and introduces the Dropout mechanism; and equation (30) represents the output layer activated using the Softmax function. Let be the Softmax probability vector of the i-th sample.

[0079] Step 5.2: Use multi-class cross-entropy loss as the training objective function and use the Adam optimizer for backpropagation to update the weights. The specific expression is as follows:

[0080] ; ;

[0081] Wherein, equation (31) is the loss function, and here... The output of the aforementioned steps is the real tag processed by one-hot encoding. Let be the predicted probability of model class k; Equation (32) is the parameter update formula based on the cross-entropy loss function. At the same time, an Early Stopping mechanism is introduced in this training process to prevent the model from overfitting.

[0082] Step 5.3: After completing model training, obtain a set of optimal parameters. At this point, the MLP model already possesses the ability to discriminate the posture state of cattle. The newly acquired gyroscope three-axis angular velocity data, after feature construction and standardization in the same manner as during the training phase, can be directly used as... Input the trained model, propagate forward to obtain:

[0083] ;

[0084] in, This represents the predicted probability that the sample belongs to the c-th pose category. Based on the discrimination, the category corresponding to the highest probability is selected as the final pose classification result.

[0085] ;

[0086] Final output This is the predicted posture category of the cow at the current moment.

[0087] Key points of this invention:

[0088] 1. Construction and extraction of multidimensional angular velocity behavioral features.

[0089] Based on the original three-axis angular velocities (gyroX, gyroY, gyroZ), a variety of characteristic variables representing motion state and change trend were designed and constructed, such as angular velocity modulus, direction amplitude ratio, dominant rotation axis, angular velocity variance and its logarithmic transformation, and direction difference of each axis, to comprehensively capture the posture and behavior characteristics of cattle.

[0090] 2. Compare the joint unsupervised clustering methods of autoencoders and Gaussian mixture models.

[0091] An improved autoencoder, which integrates reconstruction loss and contrastive loss, is used to extract low-dimensional latent representations of features, enabling the learning of the intrinsic structure of the data under unsupervised conditions. Subsequently, a Gaussian mixture model (GMM) is employed to perform cluster analysis on the latent vectors output by the encoder. Based on the posterior probability of samples under different Gaussian components, their class labels are determined, achieving label generation without manual annotation and providing effective supervision signals for pose recognition.

[0092] 3. Construct a multilayer perceptron (MLP) model for pose recognition and discrimination.

[0093] Based on existing labeled samples, a three-layer feedforward neural network is trained. The SoftMax function outputs the predicted pose class probability, and the cross-entropy loss function is used to optimize the network parameters. Simultaneously, Dropout is introduced during model training to randomly discard some neurons, preventing overfitting. Furthermore, an Early Stopping strategy is employed to automatically halt training when performance on the training set no longer improves, enhancing the model's stability and robustness. The model supports rapid pose prediction on new input data and exhibits good generalization ability.

[0094] 4. The technical approach integrates unsupervised learning and supervised learning.

[0095] Innovatively, unsupervised clustering results are used as the basis for initial labeling, and a supervised MLP model is combined to improve classification accuracy, realizing a complete closed-loop path from feature extraction to final classification for cattle posture recognition.

[0096] The beneficial effects of this invention are as follows: By collecting three-axis angular velocity data from gyroscope sensors inside cattle and combining it with algorithms such as feature construction, cluster analysis, and supervised classification, this invention achieves automatic identification of cattle posture states, resulting in the following technical effects and application advantages:

[0097] 1. Stable and reliable recognition accuracy: Compared with existing image recognition methods, this invention offers higher stability in posture recognition under complex environments. It also demonstrates strong adaptability in various scenarios, including captive breeding and grassland grazing.

[0098] 2. Low environmental dependence: The data relied upon by this invention all come from sensors inside the cattle, and are almost unaffected by external factors such as temperature changes, terrain undulations and breeding environment. This overcomes the dependence of the image system on conditions such as lighting, viewing angle and occlusion, and has higher robustness and versatility.

[0099] 3. Flexible deployment and low power consumption: Since no external camera system or high-bandwidth image acquisition equipment is required, the overall system power consumption is significantly reduced. When deployed on an edge computing terminal, the overall system power consumption is about 64% lower than that of image recognition solutions, and inference can be completed without relying on a GPU acceleration platform, making it suitable for deployment environments with limited computing power.

[0100] 4. High computational efficiency and low response latency: The algorithm design of this invention considers a low-complexity implementation path and adopts a lightweight classification model. In window recognition calculations with less than 1000 data points, the average latency is less than 0.3 seconds, which meets the requirements for real-time recognition.

[0101] 5. The algorithm structure is scalable: The present invention adopts the structure design of "unsupervised clustering + supervised classification", which can adapt to different types of cattle and future expanded posture labels. Through transfer learning or fine-tuning mechanism, the model can be quickly generalized and adapted, which significantly reduces the later maintenance cost.

[0102] 6. Intelligent Early Warning: During continuous operation, the algorithm will dynamically track and model the behavioral rhythms of the identified posture sequences, continuously assessing the activity status and posture distribution of the cattle. When cattle frequently switch postures within a short period of time, remain in rare postures for extended periods, or exhibit abnormal posture rhythms, the system can promptly trigger an early warning mechanism to assist managers in responding quickly to potential health risks.

[0103] In summary, through the aforementioned performance advantages, this invention achieves stable identification of cattle posture without relying on visual sensors, providing a more efficient and scalable technical approach for animal behavior monitoring, health early warning, and management decision-making in smart ranches.

[0104] The present invention will be further explained below with reference to the accompanying drawings and specific embodiments. Attached Figure Description

[0105] Figure 1 This is a schematic diagram of the steps of the present invention. Detailed Implementation

[0106] The following embodiments are only a part of the technical solutions of the present invention and are not intended to limit all the technical solutions of the present invention. The embodiments of the present invention are provided to further explain and illustrate the details of the technical solutions of the present invention.

[0107] See Figure 1 As shown.

[0108] A method for cattle attitude recognition based on gyroscope three-axis angular velocity signals, comprising the following steps:

[0109] Step 1: Obtain angular velocity data using the triaxial gyroscope built into the bovine rumen sensor.

[0110] Step 2: Based on the original triaxial angular velocity data gyroX, gyroY, and gyroZ, respectively, record the rotational angular velocities of the cow in the three orthogonal directions of forward / backward, left / right, and up / down; For discrete time steps, all quantities with subscript t in the text represent the value at time step t, and t-1 and t+1 represent the adjacent time steps before and after it, respectively. Based on this, the following feature variables are constructed:

[0111] 1) Angular velocity modulus (gyro_norm): This measures the combined modulus of the three-axis angular velocities at a given time point, reflecting the instantaneous motion amplitude of the cattle as a whole. The formula is defined as follows:

[0112] ;

[0113] 2) The directional amplitude ratios (gyro_xy_ratio, gyro_xz_ratio, gyro_yz_ratio) are defined by the following formula:

[0114] ;

[0115] ;

[0116] ;

[0117] in This is introduced as a stabilizing factor to prevent numerical instability caused by a denominator of zero.

[0118] 3) Angular velocity variance This is used to measure the dispersion of the three-axis angular velocity at a given time point, reflecting the degree of drastic change in the cattle's posture at that time point. The formula is defined as follows:

[0119] ; ;

[0120] 4) Dominant axis identification (gyro_max_axis): This identifies the axis with the largest absolute value among the three-axis angular velocities at the current moment. It represents the dominant direction of the cow's most significant rotation at that time. The formula is defined as follows:

[0121] ;

[0122] 5) Dynamic variation differential features, used to measure the trend of posture changes in cattle over consecutive time points, are defined by the following formula:

[0123] ;

[0124] ;

[0125] ;

[0126] ;

[0127] ;

[0128] Step 3: After feature construction, a contrastive autoencoder with fusion constraints is used to extract the low-dimensional latent representation of the samples. Then, unsupervised clustering is performed using a Gaussian Mixture Model (GMM) to achieve automatic generation of data labels. This includes the following key sub-steps:

[0129] Step 3.1: Define the time series format of the cattle angular velocity behavior feature sample set as follows: Where D=11 is the number of angular velocity features constructed in the previous step, and N is the number of samples; a contrastive autoencoder with input layer dimension D is constructed, and its structural expression is as follows:

[0130] In the encoder part, the model includes a fully connected layer with two ReLU activations and a latent representation layer with linear activation, as shown in the following structure:

[0131] ; ; ;

[0132] Among them, (12) is the first hidden layer containing 64 neurons, and the Dropout random deactivation mechanism is introduced to randomly block the output of some neurons with a 5% probability during training to improve the generalization ability of the model; (13) is the second hidden layer containing 32 neurons, and the Dropout mechanism is introduced. The encoder network transforms the input features into a latent representation, which is then used for subsequent behavior pattern learning. The decoder is a symmetric inverse structure of the encoder, and its output is the reconstructed feature samples. .

[0133] Step 3.2: Construct positive and negative sample pairs respectively, where the positive sample pairs are formed by adjacent time steps (z). t ,z t+1 The negative class consists of samples and random time intervals (z). t ,z r The sample pairs are composed of labels, expressed as follows:

[0134] ;

[0135] Step 3.3: Define the loss function and train the model. In each training round, the gradient of the total loss function with respect to the network parameters is calculated through backpropagation. The Adam optimizer is then used to iteratively update the parameters (including weights and biases) of each layer of the autoencoder based on this gradient, thereby minimizing the loss value. The specific expression is as follows:

[0136] ; ; ;

[0137] Where m=1.0 is the contrast margin threshold, and M is the number of sample pairs used in training. i ,b i () represents the indices at both ends of the i-th sample pair. The labels are constructed in the previous step. Equation (16) is the reconstruction loss function, equation (17) is the contrastive loss function, and equation (18) is the total loss function calculated by weighting the two.

[0138] ;

[0139] in, This represents all trainable parameters of the autoencoder network in the t-th training round, including the weight matrix and bias terms of each layer; This represents the learning rate, used to control the step size for each parameter update; This represents the gradient of the loss function with respect to the parameters.

[0140] Step 3.4: After the autoencoder training is complete, extract the low-dimensional vector mapped into the latent space by the encoder network. ,in This represents the trained encoder function. Based on this, a Gaussian Mixture Model (GMM) is used to cluster the latent vector (4 classes) to extract behavioral features of cattle. The specific expression is as follows:

[0141] ;

[0142] in, Let be the mixing coefficient of the k-th Gaussian component, satisfying ,and ; Let be the mean vector of the k-th Gaussian component; Let be the covariance matrix of the k-th Gaussian component; This represents a 4-dimensional Gaussian distribution.

[0143] Next, initialize the parameters mentioned above and train the model using the Expectation-Maximization (EM) algorithm. First, calculate the value of each sample z. t The posterior probability of belonging to the k-th Gaussian component:

[0144] ;

[0145] Where K is the number of Gaussian components in the Gaussian mixture model, i.e., the set number of clusters; j is the index of the Gaussian component (cluster), used to sum all the clusters. This indicates that under the current model parameters, the sample The posterior probability generated by the k-th Gaussian component. Based on Then, update the parameters. The specific update process is as follows.

[0146] ;

[0147] ;

[0148] ;

[0149] The above process is repeated iteratively. After reaching the preset maximum number of iterations, for each sample z... t The component with the highest posterior probability is selected as the clustering result. To obtain the category label of the sample. The meanings of each label are as follows: 0 - Slow movement (medium to large amplitude | low volatility), 1 - Active (medium amplitude | high volatility), 2 - Violent (large amplitude | high volatility), 3 - Stagnant movement (small amplitude | low volatility).

[0150] ;

[0151] Step 4: To ensure network convergence stability, construct features. Perform standardization processing and use the labels obtained in the previous step. One-hot encoding is performed using the following expression:

[0152] in, and denoted as the mean and standard deviation of the j-th feature, respectively.

[0153] Step 5: Using the aforementioned labeling results as supervision signals, construct a cattle posture classifier based on three-axis angular velocity features. A multi-layer perceptron model is employed, combined with an early stopping mechanism to improve the model's generalization performance. This includes the following key sub-steps:

[0154] Step 5.1: Construct a feedforward neural network model (MLP) consisting of three fully connected neural networks to supervise the modeling of pose clustering results. The specific structure is as follows:

[0155] ; ; ; ; ;

[0156] In this context, equation (26) represents the first hidden layer containing 128 neurons; equation (27) normalizes the result of equation (26) and introduces the Dropout mechanism; equation (28) represents the second hidden layer containing 64 neurons; equation (29) also normalizes the structure of equation (28) and introduces the Dropout mechanism; and equation (30) represents the output layer activated using the Softmax function. Let be the Softmax probability vector of the i-th sample.

[0157] Step 5.2: Use multi-class cross-entropy loss as the training objective function and use the Adam optimizer for backpropagation to update the weights. The specific expression is as follows:

[0158] ;

[0159] ;

[0160] Wherein, equation (31) is the loss function, and here... The output of the aforementioned steps is the real tag processed by one-hot encoding. Let be the predicted probability of model class k; Equation (32) is the parameter update formula based on the cross-entropy loss function. At the same time, an Early Stopping mechanism is introduced in this training process to prevent the model from overfitting.

[0161] Step 5.3: After completing model training, obtain a set of optimal parameters. At this point, the MLP model already possesses the ability to discriminate the posture state of cattle. The newly acquired gyroscope three-axis angular velocity data, after feature construction and standardization in the same manner as during the training phase, can be directly used as... Input the trained model, propagate forward to obtain:

[0162] ;

[0163] in, This represents the predicted probability that the sample belongs to the c-th pose category. Based on the discrimination, the category corresponding to the highest probability is selected as the final pose classification result.

[0164] ;

[0165] Final output This is the predicted posture category of the cow at the current moment.

[0166] The algorithm described in this invention, after training and iterative optimization using a total of 545,952 sample data points, ultimately obtained a posture recognition model with optimal performance. To further verify the feasibility and applicability of this algorithm in real-world scenarios, the following will incorporate two consecutive real-world data points of cattle's triaxial angular velocity collected at 18:50 on July 18, 2025, into the algorithm model. The feature construction, standardization, forward inference, and final classification results will be tracked step by step to verify the algorithm's recognition performance in a real-world data environment. The collected triaxial angular velocity data of the cattle at the previous and current moments are as follows:

[0167] A moment ago: ;

[0168] Current moment: ;

[0169] Based on the above raw data, and in accordance with the feature construction method of the present invention, each feature value is calculated step by step as follows:

[0170] 1) Angular velocity modulus (gyro_norm):

[0171] ;

[0172] 2) Directional amplitude ratios (gyro_xy_ratio, gyro_xz_ratio, gyro_yz_ratio):

[0173] ; ; ;

[0174] in This is introduced as a stabilizing factor to prevent numerical instability caused by a denominator of zero.

[0175] 3) Angular velocity variance (log_gyro_var):

[0176] ;

[0177] 4) Dominant axis identification (gyro_max_axis):

[0178] ;

[0179] 5) Dynamically changing difference features:

[0180] ; ; ; ; ;

[0181] After constructing the features, each feature variable needs to be standardized to eliminate the influence of dimensional differences on the model's discrimination results. Standardization is performed using the following formula:

[0182] ;

[0183] in, and denoted as the mean and standard deviation of the j-th feature, respectively.

[0184] Features They are respectively:

[0185] [28737.0728,0.9689,0.9837,0.9052,19.0223,0.8732,-13.9289,-363134.3279,24.7162,26.6450,32.4870]

[0186] Features They are respectively:

[0187] [8887.2107,0.8200,0.8317,0.8043,1.2063,0.8306,12579.2246,332119721.2768,26740.6191,22444.1040,22061.0091]

[0188] ; ; ; ; ; ; ; ; ; ; ;

[0189] Substituting the original features into the standardization formula, we obtain the standardized input vector:

[0190] The input vector after the above standardization process The trained model is fed into the trained Multilayer Perceptron (MLP) model. After two layers of linear transformation with ReLU activation functions and a final softmax layer, the calculation process is as follows:

[0191] ;

[0192] Due to the large dimensionality of parameters in each layer, it is not convenient to list them all. This article uses the final prediction result as an example to illustrate the prediction probabilities of each behavior category as follows:

[0193] 0 - Slow movement (medium to large amplitude | low volatility): 0.9966;

[0194] 1-Active (Medium amplitude | High volatility): 0.0034;

[0195] 2- Dramatic (Significant | High Volatility): ;

[0196] 3-Static / Dynamic (Small Amplitude | Low Fluctuation): ;

[0197] Therefore, the current posture type of the cattle is identified as 0-slow movement (medium to large amplitude | low fluctuation).

[0198] The above descriptions are merely some specific embodiments of the present invention (since the present invention includes formulas, numerical values ​​of embodiments, etc., the embodiments cannot be exhaustively listed; the scope of protection described in the present invention includes the scope of the formulas, numerical values ​​of embodiments, and other technical points of the present invention). Specific contents or common knowledge known in the solutions are not described in detail here (including but not limited to abbreviations, acronyms, and units commonly used in the art). It should be noted that the above embodiments do not limit the present invention in any way. For those skilled in the art, all technical solutions obtained by equivalent substitution or equivalent transformation fall within the scope of protection of the present invention. 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 recognizing the posture of a cattle based on three-axis angular velocity signals of a gyroscope, characterized by, The method comprises the following steps: Step 1) data acquisition and feature construction; Through the three-axis gyroscope built-in the cow rumen sensor, the rotational angular velocity data of the cow in the front-back, left-right and up-down three orthogonal directions is obtained; and the feature variables are constructed based on the angular velocity data; Step 2) unsupervised clustering label generation; An unsupervised clustering mechanism combining a self-encoder with contrast constraint and a Gaussian mixture model (GMM) is adopted; Step 3) supervised signal processing and classifier construction; The feature variables are standardized by using the mean and standard deviation method; the label generated by clustering is processed by one-hot encoding as a supervised signal; and a multi-layer perception (MLP) model is constructed to train a classifier by combining an early stopping mechanism, wherein the MLP model at least comprises an input layer, a hidden layer and an output layer; Step 4) posture discrimination; After the newly collected three-axis gyroscope angular velocity data is processed by the same feature construction and standardization method as in the training stage, the data is input into the trained MLP model, and the posture category of the cow at the current time is output.

2. The method of claim 1, wherein, In step 1) data acquisition and feature construction, the feature variables include: an angular velocity module length for representing the combined motion amplitude of the three-axis angular velocity; a direction amplitude ratio for calculating the relative size of the angular velocity of each axis by introducing a stability factor; an angular velocity variance for measuring the dispersion degree of the three-axis angular velocity; a dominant axis identification for determining the dominant rotation direction by comparing the absolute values of the three-axis angular velocity; a dynamic change difference feature for representing the posture change trend between consecutive time points.

3. The method of claim 1, wherein, Step 2) unsupervised clustering label generation comprises: a contrastive self-encoder with the input layer dimension matching the number of feature variables is constructed, wherein the encoder comprises two fully connected layers with activation functions and one linearly activated latent representation layer, and the decoder is a symmetric reverse structure of the encoder; positive and negative sample pairs are constructed, wherein the positive sample pairs are composed of adjacent time data, and the negative sample pairs are composed of current time data and random time data; a weighted total loss function is defined, including a reconstruction loss function and a contrast loss function, the network parameters are updated by a back propagation mechanism, and the Adam optimizer is used for iterative training; the low-dimensional vectors in the latent space of the trained self-encoder are extracted, the GMM model is used for clustering, the model parameters are optimized by the expectation maximization (EM) algorithm, and the sample category labels are generated.

4. The method of claim 1, wherein, In step 1) data acquisition and feature construction, based on the original three-axis angular velocity data gyroX, gyroY and gyroZ, the rotational angular velocities of the cow in the front-back, left-right and up-down three orthogonal directions are respectively obtained; Recall For discrete time steps, all quantities with subscript t represent the value at the t-th time step, and t-1, t+1 represent the adjacent previous / succeeding time steps, respectively. Accordingly, the following characteristic variables are constructed: 1) the angular velocity module length gyro_norm is used to measure the combined module length of the three-axis angular velocity at the time point, reflecting the instantaneous motion amplitude of the cow, and the definition formula is as follows: (1) 2) the direction amplitude ratio gyro_xy_ratio, gyro_xz_ratio and gyro_yz_ratio, the definition formula is as follows: ; ; ; wherein , introduced as a stabilizing factor to prevent numerical instability caused by a zero denominator; 3) Variance of angular velocity , which is used to measure the dispersion degree of three-axis angular velocity at this time point, reflects the change intensity of the posture of the cow at this time point, and the definition formula is as follows: ; ; 4) gyro_max_axis, which is used to identify the axis with the maximum absolute value in the three-axis angular velocity at the current time, i.e., representing the most significant dominant direction of the cow rotation at this time point, and the definition formula is as follows: ; 5) a dynamic change differential feature, which is used to measure the posture change trend of the cow between consecutive time points, and the definition formula is as follows: ; ; ; ; 。 5. The method of claim 1, wherein, Step 2) Unsupervised clustering label generation, set the time series form of the cattle angular velocity behavior feature sample set as where D = 11 is the number of constructed angular velocity features, and N is the number of samples. A contrastive autoencoder with an input layer dimension of D is constructed, and the structure expression is as follows: In the encoder part, the model includes a full connection layer with two layers of ReLU activation and a potential representation layer with linear activation, and the structure is as follows: ; ; ; wherein, the formula (12) is a first hidden layer containing 64 neurons; the formula (13) is a second hidden layer containing 32 neurons; is a latent representation obtained after the input features are converted through the encoder network, which is used for subsequent behavior pattern learning; The decoder part is a symmetric inverse structure of the encoder, and the output content is the reconstructed feature samples, i.e. ; Respectively construct positive and negative two kinds of sample pairs, wherein the positive class sample pair is composed of adjacent time points , and the negative class sample is composed of a sample and a random time point . Each pair of samples is accompanied by a label, and the expression is as follows: ; The loss function is defined and the model is trained, and in each training round, the gradient of the total loss function with respect to the network parameters is calculated through the back propagation mechanism, and the Adam optimizer is used to update the parameters of each layer of the autoencoder according to the gradient, so as to minimize the loss value, and the expression is as follows: ; ; ; where m = 1.0 is the margin of contrastive threshold, M is the number of sample pairs used in training, (a i ,b i ) represents the two end indices of the i-th sample pair, is the label constructed in the previous step, (16) is the reconstruction loss function, (17) is the contrastive loss function Contrastive Loss, and (18) is the total loss function calculated by weighting the two. ; wherein, denotes the whole training parameters of the autoencoder network, including the weight matrix and bias term of each layer, in the t-th round of training; denotes the learning rate, which is used to control the step size of each parameter update; denotes the gradient of the loss function with respect to the parameters; After the training of the autoencoder is completed, a low-dimensional vector mapped in the latent space by the encoder network is extracted wherein represents the trained encoder function; on this basis, the latent vector is clustered into 4 categories using a Gaussian Mixture Model, for mining the behavioral characteristics of the cattle, and the expression is as follows: ; wherein, is a mixing coefficient for the k-th Gaussian component, satisfying , and ; is a mean vector for the k-th Gaussian component; is a covariance matrix for the k-th Gaussian component; denotes a 4-dimensional Gaussian distribution; Next, the above parameters are initialized and the model is trained using the expectation maximization algorithm EM, First, compute each sample z t Posterior probability that z belongs to the kth Gaussian component: ; where K is the number of Gaussian components in the Gaussian mixture model, i.e., the number of clusters set; j is the index of the Gaussian component cluster, used to sum over all clusters; represents the sample posterior probability generated by the kth Gaussian component; based on , the parameter update is performed, and the update process is as follows, ; ; ; The above process is iterated, and after reaching a preset maximum number of iterations, for each sample z t , the component with the maximum posterior probability is selected as the clustering result , to obtain the class label to which the sample belongs , and the meanings of the labels are as follows: 0-slow movement, 1-active, 2-vigorous, and 3-static.

6. The method of claim 1, wherein, Step 3) supervised signal processing and classifier construction, using the label result as a supervised signal, constructing a cow posture classifier based on three-axis angular velocity features; using a multilayer perception model and combining an early stopping mechanism to improve the generalization performance of the model, including the following steps: A feedforward neural network model MLP composed of three fully connected neural networks is built to supervise the modeling of the posture clustering results, and the structure is as follows: ; ; ; ; ; wherein, formula (26) is a first hidden layer containing 128 neurons; formula (27) is a normalization of the result of formula (26); formula (28) is a second hidden layer containing 64 neurons; formula (29) is also a normalization of the structure of formula (28); formula (30) is an output layer activated by a Softmax function, is a Softmax probability vector of the i-th sample; A multi-class cross-entropy loss is used as the training objective function, and the Adam optimizer is used for back propagation to update the weights, and the expression is as follows: ; ; wherein, (31) is a loss function, and here is the real label outputted by the preceding step after one-hot encoding processing, is the predicted probability of the model class k; (32) is a parameter update formula based on the cross-entropy loss function; An early stopping mechanism is introduced in the training process to prevent model overfitting; After the model training is completed, a set of optimal parameters is obtained At this time, the MLP model has the ability to distinguish the posture state of the cow. For newly collected three-axis angular velocity data of the gyroscope, feature construction and standardization processing are performed in the same way as in the training stage, and the processed data is directly input into the trained model to obtain: forward propagation: ; wherein, The predicted probability that the sample belongs to the c-th posture category is represented, and the category corresponding to the maximum probability is selected as the final posture classification result according to the discrimination. ; The final output is the predicted pose class of the cow at the current time instant.

7. The method according to any one of claims 1-6 for identifying the posture of a cow.

8. A device for recognizing the posture of a cattle based on three-axis angular velocity signals of a gyroscope, characterized by It includes: A data acquisition and feature construction module for acquiring the rotational angular velocity data of a cow in the front-back, left-right, and up-down three orthogonal directions through the three-axis gyroscope built in the rumen sensor of the cow; and constructing feature variables based on the angular velocity data; An unsupervised clustering label generation module for using an unsupervised clustering mechanism combining a contrastive autoencoder and a Gaussian mixture model; A supervised signal processing and classifier construction module for standardizing the feature variables using the mean and standard deviation method; one-hot encoding the labels generated by clustering as a supervised signal; constructing a multilayer perception model MLP combined with an early stopping mechanism to train the classifier, wherein the MLP model at least includes an input layer, a hidden layer, and an output layer; A posture discrimination module for inputting the three-axis angular velocity data of the newly collected gyroscope into the trained MLP model after processing according to the consistent feature construction and standardization method in the training phase, and outputting the posture category of the cow at the current time.

9. A computer storage medium having stored thereon a computer program, characterized in that The computer program is executed by a machine to implement the steps of the method of any one of claims 1 to 6.

10. A computer device comprising a processor, a memory and a computer program stored on the memory, characterized in that, The processor implements the steps of the method of any of claims 1 to 6 when executing the computer program.

Citation Information

Patent Citations

  • Cow bone joint point extraction and posture recognition method and system based on visual sensing

    CN120071398A

  • Dairy cattle behavior classifying and judging method and device based on multi-tag-chain type ecological environment

    CN110476879A

  • Load-bearing self-adaptive adjusting system and method based on posture recognition

    CN120697028A

  • Cow behavior recognition method based on three-axis attitude angle

    CN121100826A

  • Model training method and apparatus, action recognition method and apparatus, and device and storage medium

    WO2021189952A1