A method for recognizing posture of a cow based on three-axis angular velocity signals of a gyroscope

By collecting three-axis angular velocity data using gyroscope sensors inside cattle and combining feature extraction and cluster analysis, a multilayer perceptron model is constructed. This solves the problem of the difficulty in deploying existing image recognition methods in the breeding environment, and realizes stable and low-complexity cattle posture recognition, which is suitable for different regions and diverse scenarios.

CN121542858BActive Publication Date: 2026-03-20YUNNAN ZHENTU INFORMATION TECHNOLOGY CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202610049182.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-01-15
Publication Date
2026-03-20
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 limited model generalization ability, and have high computational complexity, making them difficult to adapt to complex application scenarios in different regions and under diverse shooting conditions.

Method used

By collecting three-axis angular velocity data from gyroscope sensors in cattle, and combining feature extraction, unsupervised clustering and supervised classification, an autoencoder with fusion contrast constraints and a Gaussian mixture model are used for unsupervised clustering. A multilayer perceptron model is then constructed for attitude recognition, achieving automated attitude state recognition.

Benefits of technology

It achieves stable posture recognition in various scenarios such as captive breeding and grazing, reduces environmental dependence and computational complexity, improves recognition accuracy and adaptability, reduces deployment costs and energy consumption, and has good generalization ability and real-time response capability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121542858B_ABST
    Figure CN121542858B_ABST
Patent Text Reader

Abstract

The present application relates to a kind of based on gyroscope three-axis angular velocity signal's cattle posture recognition method, belong to the technical field of the cross of animal behavior recognition, sensor signal processing and artificial intelligence application.The method includes the following steps:1) data acquisition and feature construction;2) unsupervised clustering label generation;3) supervised signal processing and classifier construction;4) posture discrimination.This method is by collecting the three-axis angular velocity data generated by gyroscope sensor in cattle body, and is combined with feature extraction, unsupervised clustering and supervised classification etc., realizes the automatic identification to cattle posture state.The data relied on by the present application all come from in-vivo sensor signal, is almost not disturbed by temperature change, topography fluctuation and breeding environment etc.external factors, therefore has data acquisition stable, low computing overhead, deployment flexible etc.significant advantages, can be widely applied to captive, grazing etc.various breeding scenarios, can effectively improve the practicability and adaptability of cattle behavior monitoring system.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of animal behavior recognition, sensor signal processing and artificial intelligence application, especially relates to a cattle posture recognition method based on three-axis angular velocity signals of a gyroscope. BACKGROUND

[0002] In the prior art, the method for identifying the posture of a cattle mainly relies on visual perception means, that is, through monitoring images combined with a deep learning algorithm to extract skeletal key points or external contour features, and with the help of a posture identification model to complete posture classification. For example, patent application CN118736486A “Method for monitoring and identifying abnormal behavior posture of cattle” proposes a monitoring method for identifying posture based on the coordinates of the skeletal key points of the cattle in the monitoring images, thereby realizing abnormal behavior identification; and for another example, patent application CN120071398A “Method and system for extracting cattle skeletal joint points and identifying posture based on visual sensing” realizes accurate positioning and posture identification of the image area of the cattle by extracting features from video images combined with a target detection algorithm of a Transformer model.

[0003] Although the existing image recognition-based cattle posture recognition method has certain application value in a captive environment, there are still many obstacles and deficiencies in actual deployment and operation.

[0004] Firstly, such a method is highly sensitive to image input quality and target structure integrity, and the detection accuracy of skeletal key points is easily disturbed by problems such as uneven lighting, background occlusion, cattle overlap or motion blur, etc., which may cause posture recognition accuracy to decrease, target to be missed or misdetected, etc. in actual application.

[0005] Secondly, due to the wide distribution of cattle, the dispersed individual positions and the low deployment density of camera equipment, image acquisition faces problems such as discontinuous field of view and tracking interruption; at the same time, considering the weak infrastructure in a grazing environment, image acquisition equipment faces many obstacles in power supply, installation and network connection, etc., and the overall deployment and operation cost is high, which limits its application effect in a wide-area grazing environment.

[0006] In addition, such a method involves a large number of convolution operations and multi-layer self-attention calculations in the image processing and feature extraction process, and the overall computational complexity is high, which puts high requirements on the computing power and video memory of edge computing terminals; and the continuous transmission of high-resolution images and videos also puts a great pressure on the bandwidth and stability of the network, thereby limiting the deployment flexibility of the method in environments with limited computing power or poor network conditions.

[0007] Finally, such methods are mostly trained based on fixed view angles and specific data sets, and show high sensitivity when the camera installation position, shooting angle, or cattle breed changes, and the generalization ability of the model is relatively limited, making it difficult to adapt to complex application scenarios in different regional environments, breed differences, or diversified shooting conditions. SUMMARY

[0008] The present application aims to provide a cattle posture recognition method based on gyroscope three-axis angular velocity signals to solve the problems of existing image recognition methods, such as difficulty in deployment in actual breeding environments, poor environmental adaptability, strong dependence on computing power, and limited model generalization ability. This method collects three-axis angular velocity data generated by the gyroscope sensor in the cattle body, and combines feature extraction, unsupervised clustering, and supervised classification to achieve automatic recognition of cattle posture state. Since the data relied on by the present application all come from in-vivo sensor signals, they are almost not disturbed by external factors such as temperature changes, terrain undulations, and breeding environments, so they have the advantages of stable data collection, low computing overhead, and flexible deployment, and can be widely used in various breeding scenarios such as confinement and grazing, effectively improving the practicality and adaptability of the cattle behavior monitoring system.

[0009] The present application adopts the following technical solutions.

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

[0011] Step 1) Data collection and feature construction

[0012] Through the three-axis gyroscope built-in the cattle rumen sensor, the rotational angular velocity data of the cattle in the front-back, left-right, and up-down three orthogonal directions is obtained; and based on the angular velocity data, a feature variable is constructed;

[0013] Step 2) Unsupervised clustering label generation

[0014] An unsupervised clustering mechanism combining a self-encoder Contrastive Autoencoder and a Gaussian Mixture Model GMM is adopted;

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

[0016] The feature variable is standardized by using the mean and standard deviation method; the label generated by clustering is one-hot encoded as a supervised signal; a multi-layer perception model MLP is constructed, and a classifier is trained by combining an early stopping mechanism, wherein the MLP model at least includes an input layer, a hidden layer, and an output layer;

[0017] Step 4) Posture discrimination

[0018] The newly collected three-axis angular velocity data of the gyroscope is processed according to the feature construction and standardization method consistent with the training stage, and then input into the trained MLP model, and the posture category of the current moment of the cow is output.

[0019] In the step 1) data acquisition and feature construction of the application, the feature variables include: angular velocity module length, used for representing the combined motion amplitude of three-axis angular velocity;

[0020] The direction amplitude ratio is used to calculate the relative size of the angular velocity of each axis by introducing a stability factor;

[0021] Angular velocity variance is used to measure the dispersion degree of three-axis angular velocity;

[0022] Dominant axis identification is used to determine the dominant rotation direction by comparing the absolute values of three-axis angular velocity;

[0023] Dynamic change class difference feature is used to represent the posture change trend between continuous time points.

[0024] The step 2) unsupervised clustering label generation of the application comprises:

[0025] A contrastive autoencoder with an input layer dimension matching the number of feature variables is constructed, wherein the encoder comprises two fully connected layers with activation functions and a linearly activated latent representation layer, and the decoder is a symmetric inverse structure of the encoder;

[0026] A positive and negative sample pair is constructed, wherein the positive sample pair is composed of adjacent time data, and the negative sample pair is composed of current time data and random time data;

[0027] A weighted total loss function is defined, including a reconstruction loss function and a contrastive loss function, network parameters are updated through a backpropagation mechanism, and an Adam optimizer is used for iterative training;

[0028] The low-dimensional vector in the latent space of the trained autoencoder is extracted, clustering is performed through a GMM model, model parameters are optimized using the expectation maximization algorithm EM, and sample class labels are generated.

[0029] The application protects the method in the identification of the posture of the cow.

[0030] A cow posture recognition device based on three-axis angular velocity signals of a gyroscope comprises:

[0031] A data acquisition and feature construction module is used to acquire rotation angular velocity data of a cow in front-back, left-right and up-down three orthogonal directions through a three-axis gyroscope built in a cow rumen sensor; and feature variables are constructed based on the angular velocity data;

[0032] An unsupervised clustering label generation module is used to combine an unsupervised clustering mechanism of a fusion contrast constraint autoencoder (Contrastive Autoencoder) and a Gaussian mixture model (GMM).

[0033] A supervised signal processing and classifier construction module is used to standardize the feature variables by using a mean and standard deviation method, to perform one-hot encoding processing on the labels generated by clustering as a supervised signal, and to construct a multi-layer perception model (MLP) to train a classifier by combining an early stopping mechanism, wherein the MLP model at least includes an input layer, a hidden layer and an output layer.

[0034] A posture discrimination module is used to input the processed three-axis angular velocity data of the newly collected gyroscope into the trained MLP model after the three-axis angular velocity data of the newly collected gyroscope is processed according to the feature construction and standardization method consistent with the training stage, and to output the posture category of the current moment of the cattle.

[0035] A computer storage medium has a computer program stored thereon, and the computer program is executed by a machine to implement the steps of the method.

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

[0037] A cattle posture recognition method based on three-axis angular velocity signals of a gyroscope, the method includes the following steps:

[0038] Step 1: Obtain angular velocity data through a three-axis gyroscope built in a bovine rumen sensor.

[0039] Step 2: Based on the original three-axis angular velocity data gyroX, gyroY and gyroZ, the rotation angular velocities of the cattle in the front-back, left-right and up-down three orthogonal directions are respectively represented. As a discrete time step, all quantities with subscript t in the text represent the value at the tth time step, and t-1 and t+1 represent the adjacent previous and next time steps, respectively. On this basis, the following feature variables are constructed:

[0040] 1) Angular velocity norm (gyro_norm), which is used to measure the combined norm of the three-axis angular velocity at this time point, and reflects the instantaneous motion amplitude of the cattle as a whole, and the definition formula is as follows:

[0041] ;

[0042] 2) Direction amplitude ratio (gyro_xy_ratio, gyro_xz_ratio, gyro_yz_ratio), and the definition formula is as follows:

[0043] ;

[0044] ;

[0045] ;

[0046] where is introduced as a stabilizing factor to prevent numerical instability caused by a zero denominator.

[0047] 3) Angular velocity variance is used to measure the dispersion degree of the three-axis angular velocity at this time point, reflecting the change intensity of the cow's posture at this time point, and the definition formula is as follows:

[0048] ;

[0049] ;

[0050] 4) Dominant axis identification (gyro_max_axis) is used to identify the axis with the largest absolute value in the three-axis angular velocity at the current time, which represents the dominant direction of the cow's rotation at this time point. The definition formula is as follows:

[0051] ;

[0052] 5) Dynamic change type difference feature is used to measure the posture change trend of the cow between consecutive time points, and the definition formula is as follows:

[0053] ;

[0054] ;

[0055] ;

[0056] ;

[0057] .

[0058] Step 3: After the feature construction is completed, the low-dimensional latent representation of the sample is extracted by using the fusion contrastive constraint autoencoder (Contrastive Autoencoder), and then the unsupervised clustering is completed by using the Gaussian mixture model (Gaussian Mixture Model, GMM), to realize the automatic generation of data labels. The specific steps include the following key sub-steps:

[0059] Step 3.1: Set the time series form of the cow's angular velocity behavior feature sample set as 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 an input layer dimension of D is constructed, and its structure expression is as follows:

[0060] In the encoder part, the model includes a fully connected layer with two layers of ReLU activation and a latent representation layer with linear activation, and the specific structure is as follows:

[0061] ;

[0062] ;

[0063] ;

[0064] wherein equation (12) is a first hidden layer containing 64 neurons, and a Dropout random inactivation mechanism is introduced, with a probability of 5% to randomly mask the output of part of the neurons during the training process to improve the model generalization ability; equation (13) is a second hidden layer containing 32 neurons, and a Dropout mechanism is introduced; is the latent representation obtained after the input features are converted by the encoder network, which is used for subsequent behavior pattern learning. The decoder part is the symmetrical inverse structure of the encoder, and the output content is the reconstructed feature sample, i.e. .

[0065] Step 3.2: Constructing positive and negative sample pairs respectively, wherein the positive sample pair is composed of adjacent time points (z t ,z t+1 ), and the negative sample is composed of a sample and a random time point (z t ,z r ). Each pair of samples is attached with a label, and the expression is as follows:

[0066] ;

[0067] Step 3.3: Defining the loss function and training the model, in each round of training, 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 (including weights and biases) of each layer of the autoencoder according to the gradient, so as to minimize the loss value, and the specific expression is as follows:

[0068] ;

[0069] ;

[0070] ;

[0071] wherein m=1.0 is the contrast interval threshold (margin), M is the number of sample pairs used in training, and (a ib i ) represents the two-end index of the i-th sample pair, is the reconstruction loss function, (17) is the contrastive loss function, and (18) is the total loss function calculated by weighting the two.

[0072] ;

[0073] where, represents the total trainable parameters of the autoencoder network in the t-th training round, including the weight matrix and bias term of each layer; represents the learning rate, which is used to control the step size of each parameter update; represents the gradient of the loss function with respect to the parameters.

[0074] Step 3.4: After the autoencoder training is completed, extract the low-dimensional vector mapped in the latent space by the encoder network , where represents the trained encoder function. On this basis, use the Gaussian Mixture Model (GMM) to cluster the latent vector (4 classes) to mine the behavior characteristics of the cattle, and the specific expression is as follows:

[0075] ;

[0076] where, is the mixing coefficient of the k-th Gaussian component, satisfying , and ; is the mean vector of the k-th Gaussian component; is the covariance matrix of the k-th Gaussian component; represents a 4-dimensional Gaussian distribution.

[0077] Next, initialize the above parameters and use the Expectation-Maximization (EM) algorithm to train the model. First, calculate the posterior probability of each sample z t belongs to the k-th Gaussian component:

[0078] ;

[0079] 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), which is used to sum all clusters. represents the posterior probability of the sample generated by the k-th Gaussian component under the current model parameters. Based on , the parameter update is performed, and the specific update process is as follows,

[0080] ;

[0081] ;

[0082] ;

[0083] 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 , and the class label to which the sample belongs is obtained , and the meanings of the labels are as follows: 0-gradual (medium-large | low fluctuation), 1-active (medium | higher fluctuation), 2-severe (large | high fluctuation), and 3-static (small | lower fluctuation).

[0084] Step 4: To ensure network convergence stability, the constructed feature x ij is standardized, and the label obtained in the previous step is one-hot encoded, with the specific expression as follows:

[0085] ;

[0086] wherein and are the mean and standard deviation of the jth feature, respectively.

[0087] Step 5: Use the aforementioned label results as a supervisory signal to construct a cattle posture classifier based on three-axis angular velocity features. A multi-layer perceptron model (Multi-Layer Perceptron) is used, combined with an early stopping mechanism to improve model generalization performance, including the following key sub-steps:

[0088] Step 5.1: Build a feedforward neural network model (MLP) composed of three fully connected neural networks to supervise the modeling of posture clustering results, with the specific structure as follows:

[0089] ;

[0090] ;

[0091] ;

[0092] ;

[0093] ;

[0094] Wherein, (26) formula is the first hidden layer containing 128 neurons; (27) is the result of (26) formula Normalization, and introduce the Dropout mechanism; (28) formula is the second hidden layer containing 64 neurons; (29) formula is also the structure of (28) formula Normalization, and introduce the Dropout mechanism; (30) formula is the output layer activated using Softmax function, Softmax probability vector for the i th sample.

[0095] Step 5.2: adopt multi-class cross-entropy loss as training target function, and utilize Adam optimizer to update weights by back propagation, the specific expression is as follows:

[0096] ;

[0097] ;

[0098] Wherein, (31) formula is the loss function, here is the real label processed by one-hot encoding output by the preceding step, is the predicted probability of model category k; (32) formula is the parameter update formula based on cross-entropy loss function.Meanwhile, Early Stopping termination mechanism is introduced in the training process to prevent model overfitting.

[0099] Step 5.3: after completing model training, a set of optimal parameters At this time, the MLP model has the ability to distinguish the posture state of the cattle, and for the newly collected gyroscope three-axis angular velocity data, the feature construction and standardization processing are carried out in the same way as the training phase, which can be directly input into the trained model, and the forward propagation is obtained:

[0100] ;

[0101] Wherein, Indicates the predicted probability that the sample belongs to the c th posture category, and according to the discrimination, the category corresponding to the maximum probability is selected as the final posture classification result:

[0102] ;

[0103] The final output Is the predicted posture category of the cattle at the current time.

[0104] The key points of the application are:

[0105] 1. Construction and expression extraction of multi-dimensional angular velocity behavior characteristics. ​

[0106] On the basis of original three-axis angular velocity (gyroX, gyroY, gyroZ), a variety of characteristic variables representing the motion state and change trend are designed and constructed, such as angular velocity module length, direction amplitude ratio, dominant rotation axis, angular velocity variance and its logarithmic transformation, and axis direction difference, so as to comprehensively capture the posture behavior characteristics of the cattle.

[0107] 2、Comparing the joint unsupervised clustering method of autoencoder and Gaussian mixture model.

[0108] The improved autoencoder (Contrastive Autoencoder) fusing reconstruction loss and contrast loss is used to extract low-dimensional latent representation of features, and the internal structure of the data is learned under unsupervised conditions. Then, the Gaussian mixture model (GMM) is used for clustering analysis of the latent vectors output by the encoder, and the class labels are determined according to the posterior probability of the samples under different Gaussian components, so as to realize the generation of labels without manual annotation and provide effective supervision signal for posture recognition.

[0109] 3、Building a multi-layer perception (MLP) model for posture recognition and discrimination.

[0110] On the basis of existing labeled samples, a three-layer feedforward neural network is trained, the SoftMax function is used to output the predicted posture class probability, and the cross-entropy loss function is used to optimize the network parameters. At the same time, dropout is introduced in the model training to randomly discard part of the neurons to prevent overfitting; and the Early Stopping strategy is used to automatically stop training when the performance of the training set no longer improves, thereby enhancing the stability and robustness of the model. The model supports fast posture prediction for new input data and has good generalization ability.

[0111] 4、Fusion of unsupervised learning and supervised learning in technical path.

[0112] The unsupervised clustering results are innovatively used as the preliminary label basis, combined with the supervised MLP model to improve the classification accuracy, and the complete closed-loop path from feature extraction to final classification of cattle posture recognition is realized.

[0113] The present application has the following technical effects and application advantages:

[0114] 1、Stable and reliable recognition accuracy: Compared with the existing image recognition-based method, the posture recognition stability of the present application is higher in complex environment. It has strong adaptability in various scenes such as captivity and grassland grazing.

[0115] 2. Low environmental dependence: The data relied on by the present application all come from sensors in the body of the cattle, and are almost not disturbed by external factors such as temperature changes, terrain undulations and breeding environment, overcoming the dependence of image systems on light, viewing angle and shielding conditions, and having higher robustness and universality.

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

[0117] 4. High computing efficiency and low response delay: The algorithm design of the present application considers a low complexity implementation path, and uses a lightweight classification model. In a window recognition calculation of 1000 data, the average delay is less than 0.3 seconds, meeting the real-time recognition requirements.

[0118] 5. Algorithm structure has scalability: The present application uses a 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, model generalization and adaptation are quickly completed, significantly reducing the later maintenance cost.

[0119] 6. Intelligent early warning: In the process of continuous operation, the algorithm will dynamically track the identified posture sequence and model the behavior rhythm, continuously evaluate the activity state and posture distribution of the cattle. When the cattle frequently switch postures in a short time, stay in a rare posture for a long time, or have an abnormal posture rhythm, the system can trigger the early warning mechanism in time to assist the manager to quickly respond to potential health risks.

[0120] In summary, through the above performance advantages, the present application realizes stable recognition of the posture state of the cattle without relying on visual sensors, and provides a more efficient and generalizable technical path for animal behavior monitoring, health early warning and management decision-making in a smart ranch.

[0121] The present application will be further explained in conjunction with the accompanying drawings and specific embodiments. BRIEF DESCRIPTION OF DRAWINGS

[0122] Figure 1 The present application is a schematic diagram of the steps. DETAILED DESCRIPTION

[0123] The following examples are only a part of the technical solutions of the present application, and are not a limitation on all the technical solutions of the present application. The embodiments of the present application are provided to further explain and illustrate the details of the technical solutions of the present application.

[0124] See Figure 1 as shown.

[0125] A cattle posture recognition method based on three-axis angular velocity signals of a gyroscope, the method comprising the following steps:

[0126] Step 1: Obtain angular velocity data through a three-axis gyroscope built in a cattle rumen sensor.

[0127] Step 2: Based on original three-axis angular velocity data gyroX, gyroY and gyroZ, respectively corresponding to the rotational angular velocities of the cattle in the front-back, left-right and up-down three orthogonal directions; let discrete time step, all quantities with subscript t in the text represent the value at the tth time step, t-1 and t+1 represent the adjacent previous / following time steps, respectively. On this basis, the following characteristic variables are constructed:

[0128] 1) Angular velocity norm (gyro_norm), used to measure the combined norm of the three-axis angular velocity at this time point, reflecting the instantaneous motion amplitude of the cattle as a whole, defined as follows:

[0129] ;

[0130] 2) Direction amplitude ratio (gyro_xy_ratio, gyro_xz_ratio, gyro_yz_ratio), defined as follows:

[0131] ;

[0132] ;

[0133] ;

[0134] wherein , as a stability factor, is introduced to prevent numerical instability caused by a zero denominator.

[0135] 3) Angular velocity variance , used to measure the dispersion degree of the three-axis angular velocity at this time point, reflecting the change intensity of the cattle posture at this time point, defined as follows:

[0136] ;

[0137] ;

[0138] 4) Dominant axis identification (gyro_max_axis), used to identify the axis with the largest absolute value in the three-axis angular velocity at the current time, i.e. representing the most significant dominant direction of the cattle rotation at this time point, defined as follows:

[0139] ;

[0140] 5) Dynamic change type differential feature, used to measure the posture change trend of the cattle between consecutive time points, defined as follows:

[0141] ;

[0142] ;

[0143] ;

[0144] ;

[0145] ;

[0146] Step 3: After the feature construction is completed, a contrastive autoencoder is used to extract the low-dimensional latent representation of the sample, and then a Gaussian mixture model (GMM) is used to complete unsupervised clustering to realize automatic generation of data labels, which includes the following key sub-steps:

[0147] Step 3.1: Set the time series form of the cattle angular velocity behavior feature sample set as , where D=11 is the number of angular velocity features constructed in the previous step, and N is the sample number; a contrastive autoencoder with an input layer dimension of D is constructed, and its structure expression is as follows:

[0148] In the encoder part, the model includes a fully connected layer with two layers of ReLU activation and a latent representation layer with linear activation, and the specific structure is as follows:

[0149] ;

[0150] ;

[0151] ;

[0152] , where equation (12) is the first hidden layer containing 64 neurons, and a Dropout random inactivation mechanism is introduced, which randomly masks the output of part of the neurons with a probability of 5% during the training process to improve the model generalization ability; equation (13) is the second hidden layer containing 32 neurons, and a Dropout mechanism is introduced; is the latent representation obtained after the input feature is converted through the encoder network, which is used for subsequent behavior pattern learning. The decoder part is the symmetrical inverse structure of the encoder, and the output content is the reconstructed feature sample, i.e. .

[0153] Step 3.2: Constructing positive and negative sample pairs, respectively, where the positive sample pair is composed of adjacent time points (z t ,z t+1 ), and the negative sample is composed of a sample and a random time point (z t ,z r ). Each pair of samples is accompanied by a label, expressed as follows:

[0154] ;

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

[0156] ;

[0157] ;

[0158] ;

[0159] where m = 1.0 is the margin threshold, M is the number of sample pairs used in training, (a i ,b i ) represents the indices of the two ends of the i-th sample pair, and is the label 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.

[0160] ;

[0161] where represents the total trainable parameters of the autoencoder network in the t-th round of training, including the weight matrix and bias term of each layer; represents the learning rate, which controls the step size of each parameter update; represents the gradient of the loss function with respect to the parameters.

[0162] Step 3.4: After the autoencoder training is completed, extract the low-dimensional vector mapped in the latent space by the encoder network, where represents the trained encoder function. On this basis, use the Gaussian Mixture Model (GMM) to cluster the latent vector (4 classes) to mine the behavior characteristics of the cattle, with the specific expression as follows:

[0163] ;

[0164] wherein, is the mixing coefficient of the kth Gaussian component, satisfying , and ; is the mean vector of the kth Gaussian component; is the covariance matrix of the kth Gaussian component; denotes a 4-dimensional Gaussian distribution.

[0165] Next, the above parameters are initialized and the model is trained using the Expectation-Maximization (EM) algorithm. First, the posterior probability of each sample z t belongs to the kth Gaussian component is calculated:

[0166] ;

[0167] wherein 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 clusters. denotes the posterior probability of the sample generated by the kth Gaussian component under the current model parameters. Based on , the parameter update is performed, and the specific update process is as follows,

[0168] ;

[0169] ;

[0170] ;

[0171] The above process is iterated, and after reaching the preset maximum number of iterations, for each sample z t , the component with the maximum posterior probability is selected as the clustering result , and the class label to which the sample belongs is obtained . The meanings of the labels are as follows: 0 - slow motion (large amplitude | low volatility), 1 - active (medium amplitude | higher volatility), 2 - severe (large amplitude | high volatility), 3 - static (small amplitude | lower volatility).

[0172] ;

[0173] Step 4: To ensure network convergence stability, the constructed features are standardized, and the labels obtained in the previous step are subjected to one-hot encoding, with the specific expression as follows:

[0174] wherein, with are the mean and standard deviation of the j-th feature, respectively.

[0175] Step 5: Using the aforementioned label results as a supervisory signal, a three-axis angular velocity feature-based cattle posture classifier is constructed. A multi-layer perceptron model (Multi-Layer Perceptron) is used, and an early stopping mechanism is combined to improve the model's generalization performance, which includes the following key sub-steps:

[0176] Step 5.1: A feedforward neural network model (MLP) composed of three fully connected neural networks is built to supervise the modeling of the posture clustering results, with the following specific structure:

[0177] ;

[0178] ;

[0179] ;

[0180] ;

[0181] ;

[0182] wherein, equation (26) is the first hidden layer containing 128 neurons; equation (27) is the result of normalizing equation (26) and introducing the Dropout mechanism; equation (28) is the second hidden layer containing 64 neurons; equation (29) is also the structure of normalizing equation (28) and introducing the Dropout mechanism; equation (30) is the output layer activated by the Softmax function, is the Softmax probability vector of the i-th sample.

[0183] Step 5.2: A multi-class cross-entropy loss is used as the training objective function, and the Adam optimizer is used for backpropagation to update the weights, with the following specific expressions:

[0184] ;

[0185] ;

[0186] wherein, equation (31) is the loss function, and here is the real label processed by one-hot encoding output by the previous step, is 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 early termination mechanism is introduced in this training process to prevent model overfitting.

[0187] Step 5.3: 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 cattle, and for newly collected gyroscope three-axis angular velocity data, after feature construction and standardization processing in the same way as the training stage, the data can be directly input into the trained model to obtain:

[0188] ;

[0189] Among them, represents the prediction probability that the sample belongs to the c-th posture category, and the category corresponding to the maximum probability is selected as the final posture classification result according to the discrimination:

[0190] ;

[0191] The final output is the predicted posture category of the cattle at the current time.

[0192] The algorithm described in the application is trained and iteratively optimized with a total of 545,952 sample data, and finally obtains a posture recognition model with the best performance. In order to further verify the feasibility and applicability of the algorithm in the actual scene, the following will combine two time-continuous real cattle three-axis angular velocity data collected at 18:50 on July 18, 2025, input into the algorithm model, and track its feature construction, standardization, forward inference and final classification result, so as to verify the recognition effect of the algorithm in the real data environment. The three-axis angular velocity data of the cattle at the previous time and the current time collected are as follows:

[0193] Previous time: ;

[0194] Current time: ;

[0195] Based on the above raw data, according to the feature construction method of the application, the feature values are calculated as follows:

[0196] 1) Angular velocity norm (gyro_norm):

[0197] ;

[0198] 2) Direction amplitude ratio (gyro_xy_ratio, gyro_xz_ratio, gyro_yz_ratio):

[0199] ;

[0200] ​ ;

[0201] ;

[0202] where , is introduced as a stabilizing factor to prevent numerical instability caused by a zero denominator.

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

[0204] ;

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

[0206] ;

[0207] 5) Dynamic change type differential features:

[0208] ;

[0209] ;

[0210] ;

[0211] ;

[0212] ;

[0213] After completing the feature construction, each feature variable needs to be standardized to eliminate the influence of dimensional differences on the model discrimination results. Standardization is transformed using the following formula:

[0214] ;

[0215] where and are the mean and standard deviation of the jth feature, respectively.

[0216] Each feature is as follows:

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

[0218] Each feature is as follows:

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

[0220] ;

[0221] ;

[0222] ;

[0223] ;

[0224] ;

[0225] ;

[0226] ;

[0227] ;

[0228] ;

[0229] ;

[0230] ;

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

[0232] The input vector after the above standardization process The trained model is input 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:

[0233] ;

[0234] 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:

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

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

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

[0238] 3-Static (small amplitude | lower fluctuations): ;

[0239] Thus, the current moment of the cow posture type recognition is 0-creep (medium-large amplitude | low fluctuation).

[0240] The above only describes some specific embodiments of the present application (as the present application includes formulas, example values, etc., the embodiments cannot be exhausted, and the protection scope recorded in the present application includes the formulas, example values, and other technical points of the present application), and the specific contents of the scheme known in the art or common sense are not described in detail here (including but not limited to abbreviations, abbreviations, units commonly used in the art). It should be noted that the above embodiments do not limit the present application in any way, and any technical solution obtained by equivalent replacement or equivalent transformation for those skilled in the art falls within the protection scope of the present application. The protection scope claimed in this application should be subject to the content of its claims, and the specific embodiments recorded in the specification can be used to explain the content of the claims.

Claims

1. A method for cattle attitude recognition based on three-axis angular velocity signals from a gyroscope, characterized in that, The method includes the following steps: Step 1) Data acquisition and feature construction; The rotational angular velocity data of cattle in three orthogonal directions (front-back, left-right, and up-down) are acquired using a triaxial gyroscope built into the bovine rumen sensor; feature variables are constructed based on the angular velocity data; the feature variables include: angular velocity modulus, which is used to characterize the combined motion amplitude of the triaxial angular velocities; The directional amplitude ratio is calculated by introducing a stability factor to determine the relative magnitudes of the angular velocities along each axis. Angular velocity variance is used to measure the dispersion of triaxial angular velocities. Dominant axis identification: The dominant rotation direction is determined by comparing the absolute values ​​of the three-axis angular velocities. Dynamic variation differential features are used to characterize the attitude change trend between consecutive time points; Step 2) Unsupervised clustering label generation; An unsupervised clustering mechanism combining a contrastive autoencoder with a Gaussian mixture model (GMM) and including: 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. 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; 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. Extract low-dimensional vectors from the latent space of the autoencoder after training, cluster them using the GMM model, optimize the model parameters using the expectation-maximization algorithm (EM), and generate sample class labels. Step 3) Supervised signal processing and classifier construction; 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. Step 4) Attitude determination; 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.

2. The method according to claim 1, characterized in that, Step 1) Data acquisition and feature construction are based on the original triaxial angular velocity data gyroX, gyroY and gyroZ, which correspond to the rotational angular velocities of the cow in the three orthogonal directions of front-back, left-right and up-down respectively; remember For discrete time steps, all quantities with subscript t 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: 1) Angular velocity modulus gyro_norm, used to measure the combined modulus of the three-axis angular velocities at the corresponding time point in time step, reflects the instantaneous motion amplitude of the cattle as a whole, and is defined by the following formula: (1) 2) The directional amplitude ratios gyro_xy_ratio, gyro_xz_ratio, and gyro_yz_ratio are defined by the following formulas: ; ; ; in It is introduced as a stabilizing factor to prevent numerical instability caused by a denominator of zero; 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: ; ; 4) Dominant axis identification: gyro_max_axis is used to identify the axis with the largest absolute value among the three-axis angular velocities at the current moment, which represents the dominant direction of the cow's most significant rotation at that time point. The formula is defined as follows: ; 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: ; ; ; ; 。 3. The method according to claim 1, characterized in that, Step 2) Unsupervised clustering label generation: The set of time-series cattle angular velocity behavior feature samples is defined as follows. Where D=11 is the number of constructed angular velocity features, and N is the number of samples; A contrastive autoencoder with input layer dimension D is constructed, and its structural expression is as follows: 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: ; ; ; Among them, (12) is the first hidden layer containing 64 neurons; (13) is the second hidden layer containing 32 neurons; The latent representation obtained after the input features are transformed by the encoder network is used for subsequent behavior pattern learning; The decoder is a symmetric inverse structure of the encoder, and its output is the reconstructed feature samples, i.e. ; Construct two classes of sample pairs, one positive and one negative, where the positive class sample pairs are formed by adjacent time steps. The negative class is composed of samples and random time intervals. constitute; Each pair of samples is accompanied by a label, expressed as follows: ; Define the loss function and train the model. In each training round, calculate the gradient of the total loss function with respect to the network parameters through backpropagation, and use the Adam optimizer to iteratively update the parameters of each layer of the autoencoder based on this gradient, thereby minimizing the loss value. The expression is as follows: ; ; ; Where m=1.0 is the comparison interval threshold margin, M is the number of sample pairs used in training, (a i ,b i () represents the indices at both ends of the i-th sample pair. The labels constructed in the previous step; (16) is the reconstruction loss function, (17) is the contrastive loss function, and (18) is the total loss function calculated by weighting the two; ; in, This represents all training 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; 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 (Gaussian Mixture Model) is used to perform 4-class clustering on this latent vector to mine behavioral features of cattle. The expression is as follows: ; 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; Represent a 4-dimensional Gaussian distribution; Next, initialize the above parameters and train the model using the Expectation-Maximization (EM) algorithm. First, calculate z for each sample. t The posterior probability of belonging to the k-th Gaussian component: ; 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 over all clusters; This indicates that under the current model parameters, the sample The posterior probability generated by the k-th Gaussian component; based on The parameters are updated as follows. ; ; ; 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, 1 - active, 2 - intense, 3 - static movement.

4. The method according to claim 1, characterized in that, Step 3) Supervised signal processing and classifier construction: Using the label results as supervised signals, a cattle posture classifier based on three-axis angular velocity features is constructed; a multilayer perceptron model is adopted, combined with an early stopping mechanism to improve the model's generalization performance, including the following steps: A feedforward neural network model (MLP) consisting of three fully connected neural networks is constructed to supervise the modeling of pose clustering results. The structure is as follows: ; ; ; ; ; In this context, equation (26) represents the first hidden layer containing 128 neurons; equation (27) represents the normalization of the result of equation (26); equation (28) represents the second hidden layer containing 64 neurons; equation (29) also represents the normalization of the structure of equation (28); and equation (30) represents the output layer activated using the Softmax function. Let be the Softmax probability vector of the i-th sample; Multi-class cross-entropy loss is used as the training objective function, and the Adam optimizer is used for backpropagation to update the weights. The expression is as follows: ; ; 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 k be the predicted probability of model class k; (32) is the parameter update formula based on the cross-entropy loss function; An Early Stopping mechanism is introduced during training to prevent model overfitting. After completing model training, a set of optimal parameters is obtained. 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, is directly used as... Input the trained model, propagate forward to obtain: ; 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. ; Final output This is the predicted posture category of the cow at the current moment.

5. The application of the method according to any one of claims 1-4 in identifying cattle postures.

6. A cattle attitude recognition device based on three-axis angular velocity signals from a gyroscope, characterized in that, include: 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. The characteristic variables include: angular velocity magnitude, used to characterize the composite motion amplitude of the three-axis angular velocities; direction amplitude ratio, which calculates the relative magnitude of the angular velocities of each axis by introducing a stability factor; angular velocity variance, used to measure the dispersion of the three-axis angular velocities; dominant axis identification, which determines the dominant rotation direction by comparing the absolute values ​​of the three-axis angular velocities; and dynamic change differential features, used to characterize the attitude change trend between consecutive time points. An unsupervised clustering label generation module is used for an unsupervised clustering mechanism that combines a contrastive autoencoder with a Gaussian mixture model (GMM). This includes: constructing a contrastive autoencoder with an input layer dimension matching the number of feature variables, where the encoder contains two fully connected layers with activation functions and one linearly activated latent representation layer; the decoder is a symmetric inverse structure of the encoder; constructing positive and negative sample pairs, where positive sample pairs consist of data from adjacent time steps, and negative sample pairs consist of data from the current time step and random time steps; defining a weighted total loss function, including a reconstruction loss function and a contrastive loss function, updating network parameters through backpropagation, and iteratively training using the Adam optimizer; extracting low-dimensional vectors from the latent space of the trained autoencoder, clustering them using the GMM model, optimizing model parameters using the expectation-maximization (EM) algorithm, and generating sample class labels. 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. 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.

7. A computer storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a machine, it implements the steps of the method as described in any one of claims 1 to 4.

8. A computer device comprising a processor, a memory, and a computer program stored in the memory, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 4.

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

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

    CN121100826A