Pig behavior identification method based on feature point detection
By improving the YOLOv8-Pose model, the YOLO-ASF-P2 and CNN-Bi-GRU models are constructed, and the problems of complex and low efficiency of pig feature extraction are solved, high-precision pig feature point detection and behavior recognition are achieved, and lightweight and efficient solutions are provided.
Patent Information
- Application Number
- CN202411374698.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-09-29
AI Technical Summary
The existing pig behavior recognition and analysis methods have the problem that pig feature extraction methods are complex and easy to obtain redundant feature information. The pig body shape is not rigid and has a variety of postures, resulting in low feature extraction efficiency.
A pig behavior recognition method based on feature point detection is proposed. By improving the YOLOv8-Pose model, the pig feature point detection model YOLO-ASF-P2 is constructed. Combined with the scale feature fusion module, the triple feature encoding module and the channel and position attention mechanism module, the feature point timing information of key parts of the pig is extracted, and the pig behavior recognition model CNN-Bi-GRU is constructed. The pig's three behaviors are identified through the bidirectional gated circulation unit and attention mechanism.
It realizes high-precision recognition of pig feature point detection, improves the accuracy of pig behavior recognition, and provides a lightweight and efficient solution suitable for deployment in resource-constrained environments.
Smart Images

Figure CN119693996A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of pig behavior recognition, and in particular to a pig behavior recognition method based on feature point detection. Background Art
[0002] With the booming development of technologies such as machine vision and deep learning, today's pig farming industry is shifting towards intensive and intelligent development. Pig behavior can reflect its health and welfare. By monitoring and analyzing pig behavior, diseases, stress reactions and other abnormal conditions can be detected in a timely manner, so that corresponding measures can be taken to improve the health level and production efficiency of the pig herd. The traditional method of manually monitoring pig behavior is time-consuming and labor-intensive and easily affected by human subjective factors. Using machine vision and deep learning technology to monitor and analyze pig behavior can not only provide a large amount of real-time and accurate pig information, but also protect the welfare of pigs, providing strong support for ensuring pig health and improving breeding efficiency.
[0003] The existing pig behavior recognition and analysis methods have the problems of complex pig feature extraction methods and easy acquisition of redundant feature information. The physical feature information of pigs during daily activities reflects their behavioral state. In the process of pig feature extraction, the pig's body is non-rigid and its posture is changeable, which also makes the existing pig feature extraction method complex and inefficient. Summary of the invention
[0004] The purpose of this section is to summarize some aspects of embodiments of the present invention and briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this section and the specification abstract and the invention title of this application to avoid blurring the purpose of this section, the specification abstract and the invention title, and such simplifications or omissions cannot be used to limit the scope of the present invention.
[0005] In view of the above existing problems, the present invention is proposed.
[0006] Therefore, the technical problem solved by the present invention is to provide a method for identifying pig behavior based on feature point detection.
[0007] To solve the above technical problems, the present invention provides the following technical solutions: a method for pig behavior recognition based on feature point detection, comprising the following steps: constructing a pig feature point detection dataset and a pig behavior recognition dataset; modifying the Neck part of the original YOLOv8-Pose model, combining the detail feature information of the small target provided by the P2 layer of the Backbone part of the original model, introducing the ASF architecture, integrating the scale feature fusion module, the triple feature encoding module and the channel and position attention mechanism module in the ASF architecture, and optimizing the target box loss function to establish a pig feature point detection model YOLO-ASF-P2; using the established pig feature point detection model YOLO-ASF-P2 to extract the feature point time series information of the key parts of the pig; constructing a pig behavior recognition model CNN-Bi-GRU in combination with the feature point time series information; the pig behavior recognition model CNN-Bi-GRU flexibly captures the pig feature point information through a bidirectional gated recurrent unit and an attention mechanism and performs weighted processing, effectively combines the time series characteristics of the pig feature points, and efficiently recognizes the three behaviors of sitting, standing and lying of the pig.
[0008] Preferably, based on the feature information of the P2 level, the step of fully fusing the multi-scale feature information through the scale feature fusion module includes: using a 1×1 convolution module to adjust the number of channels of the P4 and P5 level feature maps to the number of channels of the P3 level feature map, and adjusting the number of channels of the P3 and P4 feature levels to the number of channels of the P2 level feature map; using the nearest neighbor interpolation method to adjust the size of the P4 and P5 level feature maps to the size of the P3 level feature map, and adjusting the size of the P3 and P4 level feature maps to the size of the P2 level feature map; adding an additional depth dimension to the dimension of each level feature layer, changing it from a 3D tensor to a 4D tensor; connecting the 4D feature maps along the depth dimension to form a 3D feature map for subsequent convolution; using 3D convolution, 3D batch normalization and SiLU activation function to complete scale feature extraction.
[0009] Preferably, the triple feature encoding module is used to adjust the number of channels and spatial resolution of the feature map, including the following steps: for a large-size feature map, convolution, batch normalization and SiLU activation function are used to operate it, so that the number of channels of the large-size feature map becomes twice that of the input, and then a hybrid structure of maximum pooling and average pooling is used for operation; for a small-size feature map, a convolution module is used to reduce its number of channels to half of the original, and then the nearest neighbor interpolation method is used for upsampling operation, and the feature map is filled with information of adjacent pixels. Finally, the large, medium and small feature maps of the same dimension are convolved separately, and output after splicing in the channel dimension.
[0010] Preferably, the channel and position attention mechanism module integrates detailed feature information output from the scale feature fusion module and the triple feature encoding module, and also includes that the channel and position attention mechanism module includes a channel attention network and a position attention network, the channel attention network replaces global cross-channel interaction with local cross-channel interaction, and the position attention network enhances the network's perception of feature point positions by considering the spatial structure information of the feature map.
[0011] Preferably, the channel attention network includes the following processing steps: performing a global average pooling operation on the input feature map, fusing the average values of each channel obtained by the 1×1 convolution layer, normalizing the weights by a Sigmoid function, and multiplying the normalized weights by the original input feature map channel by channel to finally obtain a weighted feature map, wherein the size k of the convolution kernel is set by a one-dimensional convolution and a nonlinear mapping relationship, which can more effectively capture cross-channel dependencies, and the size k of the convolution kernel is proportional to the channel dimension C, which is an exponential multiple of 2, and the relationship between k and the channel dimension C is as follows:
[0012] C=α(k)=2 (γ.k+b)
[0013] In the formula, γ and b are scaling parameters that control the ratio of the size of the convolution kernel k to the channel dimension C. The expression of k can be obtained through the inverse function:
[0014]
[0015] In the formula, |·| odd It means taking the odd value of the nearest neighbor, γ is set to 2, and b is set to 1.
[0016] Preferably, the position attention network includes the following processing steps: combining the output of the channel attention mechanism with the output of the scale feature fusion module as input, extracting important spatial information of the pig feature points, dividing the input feature map into two parts according to width and height, and performing average pooling in the width and height directions of the feature map, respectively, to retain the spatial structure information of the feature map, as follows:
[0017]
[0018] In the formula, p w and p h Represent the results of horizontal and vertical pooling respectively, W and H are the width and height of the input feature map respectively, and E(i,j) is the value of the input feature map at position (i,j); the results of horizontal pooling and vertical pooling are spliced in the channel dimension, and the spliced results are convolved to obtain the fused feature map, as shown in the following formula:
[0019] P(a w ,a h )=Conv[Concat(p w ,p h )]
[0020] In the formula, P(a w ,a h ) represents the output result of the convolution operation, Conv represents the convolution operation, and Concat represents the serial concatenation operation; the fused feature map is divided into two feature maps in the channel dimension, representing the width and height attention respectively, as shown in the following formula:
[0021] S w =Split(a w )
[0022] S h =Split(a h )
[0023] In the formula, S w and S h are the width and height after segmentation; for S w and S h Sigmoid activation function is applied respectively to obtain the normalized attention weights.
[0024] Preferably, the target box loss function includes the following optimization steps, replacing the original loss function with the EIoU loss function, the formula is as follows:
[0025]
[0026] Where IoU is the intersection over union ratio between the real target box and the predicted target box, ρ 2 (b,b gt ) is the Euclidean distance between the center of the predicted target box and the center of the true target box, w and h are the width and height of the predicted target box, respectively. gt and h gt are the width and height of the real bounding box, w c and h c are the width and height of the minimum outer bounding box of the real target box and the predicted target box, respectively. is the diagonal distance of the minimum outer bounding box.
[0027] Preferably, the pig behavior recognition model CNN-Bi-GRU is constructed based on a gated recurrent unit, wherein the Bi-GRU unit is composed of two independent GRUs, which process data forward and backward according to the time series respectively, and includes the following steps: first, a convolutional layer is used to extract local features of the time series feature point data; then, the Bi-GRU unit is applied to model the time series, and an attention mechanism is applied to the output of the Bi-GRU unit to generate a weighted output; finally, the pig behavior category is output through a fully connected layer.
[0028] Preferably, h in the Bi-GRU unit t is the output state, which is realized as follows:
[0029]
[0030] In the formula, are the states of the forward hidden layer and the backward hidden layer at time t, are the weights of the forward hidden layer and the backward hidden layer states, respectively, and b t is the bias term.
[0031] Preferably, the pig behavior recognition model CNN-Bi-GRU includes the following steps: in the forward propagation process of information, the attention mechanism module in the pig behavior recognition model CNN-Bi-GRU weights the importance of each time step to capture the key information in the sequence; linearly transforms the input, and applies the Softmax activation function to calculate the attention weight; finally, multiplies the input and the weight element by element, and returns the weighted result, which is specifically implemented as follows:
[0032] a=W·x+b
[0033] a probs =Softmax(a)
[0034] Output=x⊙a probs
[0035] In the formula, x represents the output of the Bi-GRU unit, a represents the result after applying a linear transformation to the input, and a probs represents the obtained attention weight, and ⊙ represents element-wise multiplication.
[0036] The beneficial effects of the present invention are as follows: first, the detection accuracy of the pig feature point detection model YOLO-ASF-P2 is 92.5%, the recall rate is 90%, the average precision (AP50-95) is 68.2%, the number of floating-point operations is 39.2GFLOPs, and the model parameter amount is 18.4M; second, the average recognition accuracy of the pig behavior recognition model CNN-Bi-GRU for the three behaviors of sitting, standing and lying of pigs is 96%. The proposed pig feature point detection model has high accuracy and is lightweight, and can effectively cope with the challenge of accurate detection of feature points caused by the changeable postures of pigs; third, at the same time, the pig behavior recognition model can effectively recognize the three behaviors of sitting, standing and lying of pigs in combination with the time domain information of the pig feature points, providing a new idea for the behavior recognition of pigs. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor. Among them:
[0038] Figure 1 This is a schematic diagram of the pig characteristic points marked in the present invention;
[0039] Figure 2 It is a schematic diagram of the missing and blocked characteristic points of live pigs according to the present invention;
[0040] Figure 3 It is a schematic diagram of three kinds of behavior images of pigs according to the present invention;
[0041] Figure 4 Schematic diagram of the YOLO-ASF-P2 model structure of the present invention;
[0042] Figure 5 It is a structural schematic diagram of the triple feature encoding module of the present invention;
[0043] Figure 6 Schematic diagram of the structure of the channel and position attention mechanism module of the present invention;
[0044] Figure 7 It is a structural schematic diagram of the GRU structure of the present invention;
[0045] Figure 8 It is a structural schematic diagram of the CNN-Bi-GRU model structure of the present invention;
[0046] Fig. 9 A schematic diagram of a target frame loss value variation curve according to the present invention;
[0047] Fig.10 This is a heat map of the detection performance of different models described in the present invention. DETAILED DESCRIPTION
[0048] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary persons in the art without creative work should fall within the scope of protection of the present invention.
[0049] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0050] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.
[0051] The present invention is described in detail with reference to schematic diagrams. When describing the embodiments of the present invention, for the sake of convenience, the cross-sectional diagrams showing the device structure will not be partially enlarged according to the general scale, and the schematic diagrams are only examples, which should not limit the scope of protection of the present invention. In addition, in actual production, the three-dimensional dimensions of length, width and depth should be included.
[0052] At the same time, in the description of the present invention, it should be noted that the directions or positional relationships indicated by the terms "upper, lower, inner and outer" are based on the directions or positional relationships shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore cannot be understood as limiting the present invention. In addition, the terms "first, second or third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0053] In the present invention, unless otherwise clearly specified and limited, the terms "install, connect, connect" should be understood in a broad sense, for example: it can be a fixed connection, a detachable connection or an integral connection; it can also be a mechanical connection, an electrical connection or a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0054] Example 1
[0055] The physical feature information of pigs during their daily activities reflects their behavioral state. In the process of extracting pig features, due to the non-rigid body and changeable posture of pigs, the existing pig feature extraction method is complex and inefficient. The existing pig behavior recognition and analysis methods have the problem that the pig feature extraction method is complex and redundant feature information is easily obtained. To this end, this embodiment first improves the YOLOv8-Pose model, proposes a pig feature point detection model YOLO-ASF-P2, and extracts the feature point information of key parts of the pig's body. By applying the small target feature information provided by the P2 detection layer in the model backbone to the scale feature fusion module and the triple feature encoding module, the detail information of the small-scale feature points is saved, and the ability of the model to fuse multi-scale feature information is improved. While improving the accuracy of pig feature point detection, the number of model parameters is significantly reduced, which can effectively deal with the situation where the feature points of pigs change in scale due to movement and other states and is easy to deploy; then, based on the feature point detection, the pig behavior recognition model CNN-Bi-GRU is constructed, and by analyzing a large amount of time series information of the feature points of pigs during movement, the effective recognition of the three behaviors of pigs sitting, standing and lying is realized. Specifically, this embodiment proposes a pig behavior recognition method based on feature point detection, comprising the following steps:
[0056] S1: Construct pig feature point detection dataset and pig behavior recognition dataset;
[0057] S2: Modify the Neck part of the original YOLOv8-Pose model, combine the detail feature information of small targets provided by the P2 layer of the Backbone part of the original model, introduce the ASF architecture, integrate the scale feature fusion module, the triple feature encoding module, and the channel and position attention mechanism module in the ASF architecture, and optimize the target box loss function to establish the pig feature point detection model YOLO-ASF-P2;
[0058] S3: Using the established pig feature point detection model YOLO-ASF-P2 to extract the time series information of feature points of key parts of the pig;
[0059] S4: Constructing a pig behavior recognition model CNN-Bi-GRU based on the time series information of the feature points;
[0060] S5: The pig behavior recognition model CNN-Bi-GRU flexibly captures the pig feature point information and performs weighted processing through a bidirectional gated recurrent unit and an attention mechanism, effectively combines the temporal characteristics of the pig feature points, and efficiently recognizes the three behaviors of sitting, standing, and lying of the pigs.
[0061] In more detail, in step S1, that is, constructing a pig feature point detection data set and a pig behavior recognition data set, this embodiment includes three parts: data collection, pig feature point detection data set construction, and pig behavior data set construction. Among them, the data collection implementation method is: the pig data are collected from Zhejiang Qingzhu Agriculture and Animal Husbandry Co., Ltd. and Zhejiang Hangzhou Gaohong Pig Farm. The pig breeds are all Landrace pigs, with about 7-10 heads per pen. The overall space of the pig house is rectangular, with a water trough, a food trough and a ventilation device. In order to facilitate the all-round collection of pig data, Hikvision cameras are installed at multiple angles such as the top and side of the pig house, mainly collecting data during the daytime when pigs are active frequently (7 am to 5 pm), and a total of 52 videos and 1026 original images are collected.
[0062] The construction of the pig feature point detection dataset is implemented as follows:
[0063] The open source data annotation tool X-AnyLabeling is used to annotate the pig target frame and feature points. The target frame information mainly includes the coordinates of the target frame center point and the width and height of the target frame; the feature point information includes the coordinates of the point and the visibility of the feature point. Figure 1 As shown, there are 14 key points in total, including the pig's nose, forehead, shoulder, body (usually the back), buttocks, tail, left forelimb, left front hoof tip, right forelimb, right front hoof tip, left hind limb, left hind hoof tip, right hind limb and right hind hoof tip.
[0064] The feature point marking rules are as follows: a) For the missing feature points caused by the pig's body parts leaving the camera screen, the missing feature points are not marked and the visibility of the point is set to 0, such as Figure 2 As shown in the upper right rectangular box in the left picture. b) For the case where the pig feature points appear normally, the feature points are marked and the visibility is set to 1. c) For the case where the pig body parts are in the picture but not exposed due to the camera angle or social interaction behavior, the blocked feature points are marked and annotated as 2, such as Figure 2 As shown in the rectangular box in the lower right corner of the right picture.
[0065] In order to improve the generalization ability and detection accuracy of the pig feature point detection model, this embodiment uses a combination of Gaussian noise, salt and pepper noise, image sharpening, pixel hollowing, brightness adjustment, image translation and other methods to enhance the image data. After offline enhancement, a total of 3028 image data are saved, and the training set, validation set and test set are divided into a ratio of 6:2:2 to construct a pig feature point detection data set.
[0066] The pig behavior dataset is constructed as follows:
[0067] In order to obtain the continuous time series of pig behavior data, the tracking branch of the YOLOv8 model is first used to track the pigs in the video, and the pixels around the target pigs are differentiated from the pixels in other areas of the picture, so as to extract the images of the three behaviors of the pigs standing, sitting and lying, such as Figure 3 Then, the pig feature point detection model is used to obtain the feature point data of pigs based on time series. A total of 109,740 time series data of pigs' sitting, standing, and lying behaviors are saved. After preprocessing operations such as deduplication, the training set, validation set, and test set are divided into a ratio of 6:2:2 to construct a pig behavior recognition dataset.
[0068] Furthermore, the construction of the pig feature point detection model includes YOLOv8, which is a powerful target detection model. It inherits the network structure design concept of the YOLO series model. YOLOv8-Pose is a branch of the YOLOv8 model designed to handle pose estimation tasks. It is mainly used to identify the key feature points of the research object in the image, output the [x, y] coordinates and confidence scores of each point, and detect and identify the 17 key points of the human body joints.
[0069] However, when pigs are in motion, their joints are prone to blurring and distortion, and the scale of target feature points is reduced, so it is difficult to accurately detect them by directly applying the YOLOv8-Pose model. In order to improve the detection accuracy of pig feature points, the YOLOv8-Pose model is improved as follows in this embodiment.
[0070] First, the Neck part of the original model is modified, and the detailed feature information of small targets provided by the P2 layer of the Backbone part of the original model is combined to introduce an improved ASF architecture. The scale sequence feature fusion module (SSFF) in this architecture can combine global or high-level semantic information from multi-scale feature maps, and the triple feature encoding module (TFE) can capture the local fine details of small targets. The integration of local and global feature information can produce more accurate target features. The channel and position attention mechanism (CPAM) can capture and refine the spatial positioning information related to small targets and improve the positioning accuracy of the model. Then, four prediction heads are used to predict image features to generate the target category, bounding box coordinates, location information of 14 feature points of pigs, and confidence. The structure of the improved pig feature point detection model YOLO-ASF-P2 is shown below. Figure 4As shown in the figure, the red line part is the improvement. In the figure, Stack is a module for stacking features of different scales, 3D Conv is a three-dimensional convolution layer using a 1x1x1 convolution kernel, BN is batch normalization, SiLU is an activation function, Concat is a feature connection module, Bbox Loss and Cls Loss are bounding box loss and classification loss respectively, Split is a feature map segmentation module, Bottleneck is a deep convolution module, and Conv2d is a single convolution module.
[0071] Furthermore, in this embodiment, the multi-scale feature fusion module (SSFF) is used to process the multi-scale information of feature maps at all levels in the image pyramid. This module uses the Gaussian kernel and the nearest neighbor interpolation method to align the multi-scale feature maps with different downsampling multiples to the same resolution as the high-resolution feature map, thereby fully extracting the information of the deep feature map and the shallow feature map of the same dimension.
[0072] First, given the feature maps of the P2, P3, P4, and P5 detection layers, they are convolved using Gaussian kernels with gradually increasing standard deviations, as follows:
[0073] F σ (i,j)=∑ u ∑ v f(iu,iv)×G σ (u,v) (1)
[0074]
[0075] In the formula, f represents the two-dimensional feature map, σ is the standard deviation, and i, j represent the output feature map F σ The coordinates of the pixels in, u and v represent the Gaussian filter G σ The position coordinates in the kernel window, G σ is a Gaussian filter, F σ is a two-dimensional Gaussian filter G with a standard deviation of σ σ The result of smoothing the feature map, where x and y are the coordinates of the pixels in the image.
[0076] It can be seen from formula (1) that as the standard deviation σ increases, the smoothing effect of the Gaussian filter is stronger and it can better smooth the details in the feature map.
[0077] Then, based on the feature information at the P2 level, the SSFF module is used to fully integrate the multi-scale feature information to improve the model's detection effect on pig feature points. The specific implementation steps are:
[0078] ① Using a 1×1 convolution module, the number of channels of the P4 and P5 level feature maps is adjusted to 256 (the number of channels of the P3 level feature map), and the number of channels of the P3 and P4 level feature maps is adjusted to 128 (the number of channels of the P2 level feature map).
[0079] ② Use the nearest neighbor interpolation method to resize the P4 and P5 level feature maps to the size of the P3 level feature map, and resize the P3 and P4 level feature maps to the size of the P2 level feature map.
[0080] ③Use the unsqueeze method to add an additional depth dimension to the dimension of each level of feature layer, changing it from a 3D tensor to a 4D tensor.
[0081] ④Connect the 4D feature maps along the depth dimension to form a 3D feature map for subsequent convolution.
[0082] ⑤ Use 3D convolution, 3D batch normalization and SiLU activation function to complete scale feature extraction.
[0083] Further, in this embodiment, the triple feature encoding module (TFE) is used to balance the detail information of feature maps of different scales. By adjusting the number of channels and spatial resolution of the feature map, the module can avoid the model from losing the key features of the target during the feature fusion process and improve the detection performance of the model. For large-size feature maps, the TFE module uses convolution, batch normalization and SiLU activation function to operate it, so that the number of channels of the large-size feature map becomes twice that of the input. By expanding the number of channels, the capacity of its feature map can be increased, thereby capturing more feature patterns. Then a hybrid structure of maximum pooling and average pooling is used to operate, reduce the spatial dimension characteristics of the feature map and achieve translation invariance, and enhance the robustness of the network to spatial changes in the input feature map. For small-size feature maps, the convolution module is first used to reduce the number of channels to half of the original, reduce the computational complexity and retain important semantic information, and then the nearest neighbor interpolation method is used for upsampling operations, and the feature map is filled with information from adjacent pixels, which helps to prevent the loss of feature information of small targets. Finally, the three feature maps of the same dimension, large, medium and small, are convolved respectively, and output after splicing in the channel dimension. The structure of the TFE module is as follows Figure 5 In the figure, Large, Medium, and Small represent feature maps of large, medium, and small scales, C represents the number of channels, S represents the size of the feature map, ConvBNSiLU is a convolution module, MaxPooling is a maximum pooling module, Downsapling represents the downsampling part, Add represents the feature map addition operation, Nearest represents the nearest neighbor interpolation module, Upsampling represents the upsampling part, and Concat represents the feature fusion operation.
[0084] In order to effectively extract the important feature information contained in different channels of the feature map, the channel and position attention mechanism (CPAM) is used to integrate the detailed feature information output from the SSFF module and the TFE module. CPAM consists of a channel attention network and a position attention network. The channel attention network replaces the global cross-channel interaction with the local cross-channel interaction, which can avoid the problem of complex calculation caused by inefficiently capturing the dependencies between all channels; the position attention mechanism enhances the network's perception of the feature point position by considering the spatial structure information of the feature map. The structure of CPAM is shown in Figure 1. Figure 6 As shown in the figure, AvgPool represents the average pooling module, Conv1D represents the 1×1 convolutional layer, and Sigmoid is the activation function. Its specific implementation is as follows:
[0085] ① The channel attention network performs a global average pooling operation on the input feature map, fuses the average values of each channel obtained by the 1×1 convolution layer, normalizes the weights through the Sigmoid function, and multiplies the normalized weights by the original input feature map channel by channel to finally obtain the weighted feature map. Among them, the size of the convolution kernel k is set through one-dimensional convolution and nonlinear mapping relationship, which can more effectively capture cross-channel dependencies. The size of the convolution kernel k is proportional to the channel dimension C, which is an exponential multiple of 2, so the relationship between k and the channel dimension C is as follows:
[0086] C=α(k)=2 (γ.k+b) (3)
[0087] Where γ and b are scaling parameters that control the ratio of the size of the convolution kernel k to the channel dimension C, respectively.
[0088] The expression of k can be obtained through the inverse function:
[0089]
[0090] In the formula, |·| odd It means taking the odd value of the nearest neighbor, γ is set to 2, and b is set to 1.
[0091] ② The position attention network combines the output of the channel attention mechanism with the output of the SSFF module as input to extract important spatial information of pig feature points. The position attention mechanism first divides the input feature map into two parts according to width and height, and performs average pooling in the width and height directions of the feature map to retain the spatial structure information of the feature map. The specific calculation is as follows:
[0092]
[0093] In the formula, p w and p hRepresent the results after horizontal and vertical pooling respectively, W and H are the width and height of the input feature map, respectively, and E(i,j) is the value of the input feature map at position (i,j).
[0094] ③ The results of horizontal pooling and vertical pooling are concatenated in the channel dimension, and a convolution operation is performed on the concatenated results to obtain a fused feature map, as shown in formula (7):
[0095] P(a w ,a h )=Conv[Concat(p w ,p h )](7)
[0096] In the formula, P(a w ,a h ) represents the output result of the convolution operation, Conv represents the convolution operation, and Concat represents the serial concatenation operation.
[0097] ④ Split the fused feature map into two feature maps in the channel dimension, representing the width and height attention respectively, as shown in equations (8) and (9):
[0098] S w =Split(a w ) (8)
[0099] S h =Split(a h ) (9)
[0100] In the formula, S w and S h are the width and height after segmentation respectively.
[0101] ⑤ For S w and S h Sigmoid activation function is applied respectively to obtain the normalized attention weights.
[0102] Furthermore, although the CIoU loss function used in the YOLOv8-Pose model before the improvement takes into account the overlapping area, center point distance and aspect ratio of the target box regression, its shape analysis of the target box is inaccurate. In order to make the detection more accurate, the original loss function is replaced with the EIoU loss function. While considering the impact of the overlapping area and center point distance on the loss function, EIoU also considers the impact of the width and height of the target box on the loss. It not only pays attention to the overlapping area between the target boxes, but also pays attention to other non-overlapping areas, which can improve the detection effect of the target. The formula for EIoU loss is as follows:
[0103]
[0104] Where IoU is the intersection over union ratio between the real target box and the predicted target box, ρ 2 (b,b gt ) is the Euclidean distance between the center of the predicted target box and the center of the true target box, w and h are the width and height of the predicted target box, respectively. gt and h gt are the width and height of the real bounding box, w c and h c are the width and height of the minimum outer bounding box of the real target box and the predicted target box, respectively. is the diagonal distance of the minimum outer bounding box.
[0105] Furthermore, the construction of the pig behavior recognition model CNN-Bi-GRU includes: Recurrent neural network (RNN) is a neural network specially used to process sequence data. In the process of information back propagation, gradient vanishing or gradient explosion will occur, resulting in short-term memory. GRU (gated recurrent unit, GRU) is a variant of RNN. It controls the flow of information by introducing a gating mechanism. It only needs to update and reset the gate and use the hidden state to pass information. The structure is simple and effectively solves the problem of short-term memory, allowing the model to capture long-term dependencies. The structure of GRU is as follows: Figure 7 As shown in the figure, x t , h t are the input, historical candidate state and hidden state of the model at time t, respectively, t represents the update gate, which is used to control the weight of the historical state and the current input information, r t Represents the reset gate, which is used to reset the information of the model in the current state, and σ is the sigmoid function.
[0106] The implementation of GRU is as follows:
[0107] z t =σ(W z ×[h t-1 ,x t ])(11)
[0108] r t =σ(W r ×[h t-1 ,x t ])(12)
[0109]
[0110] Where W z , W r and W h is the parameter matrix obtained by back propagation of the neural network.
[0111] In order to combine the feature information in the time domain to efficiently identify the behavior of pigs, a pig behavior recognition model CNN-Bi-GRU was constructed based on the gated recurrent unit. Among them, the Bi-GRU (bidirectional gated recurrent unit, Bi-GRU) unit is composed of two independent GRUs, which process data forward and backward according to the time series respectively. Through this bidirectional structure, the Bi-GRU unit can simultaneously capture the forward and backward information of the sequence data, thereby improving the model's ability to understand the context. The model first uses the convolutional layer to extract the local features of the time series feature point data, and then applies the Bi-GRU unit for time series modeling, and applies the attention mechanism to the output of the Bi-GRU unit to generate a weighted output, and finally outputs the pig behavior category through the fully connected layer. The CNN-Bi-GRU model structure is as follows Figure 8 As shown in the figure, Conv1d is a one-dimensional convolution operation, Dropout is a regularization operation, AttentionBlock is an attention mechanism module for implementing weighted output, FCLayer is a fully connected layer, and LeakyReLU and Softmax are activation functions.
[0112] Figure 8 In the Bi-GRU unit, h t is the output state, which is implemented as follows:
[0113]
[0114]
[0115] In the formula, are the states of the forward hidden layer and the backward hidden layer at time t, are the weights of the forward hidden layer and the backward hidden layer states, respectively, and b t is the bias term.
[0116] In the forward propagation of information, the AttentionBlock attention mechanism module in CNN-Bi-GRU can weight the importance of each time step to better capture the key information in the sequence. It first performs a linear transformation on the input, then applies the Softmax activation function to calculate the attention weight, and finally multiplies the input and the weight element by element, returning the weighted result. The specific implementation is as follows:
[0117] a=W·x+b(18)
[0118] a probs =Softmax(a) (19)
[0119] Output=x⊙aprobs (20)
[0120] In the formula, x represents the output of the Bi-GRU unit, a represents the result after applying a linear transformation to the input, and a probs represents the obtained attention weight, and ⊙ represents element-wise multiplication.
[0121] The pig behavior recognition method based on feature point detection proposed in this embodiment uses YOLO-ASF-P2 to combine the large-resolution feature map of the P2 layer in the YOLOv8-Pose backbone network to provide more target features, and applies the scale feature fusion module to align the feature maps of different scales to improve the model's ability to fuse multi-scale feature information; secondly, a triple feature encoding module is applied to balance the details of multi-scale feature information to avoid the model from losing target features; finally, the spatial information of feature points is captured through the channel and position attention mechanism to accurately detect the feature points of pigs. CNN-Bi-GRU flexibly captures the feature point information of pigs and performs weighted processing through bidirectional gated recurrent units and attention mechanisms, effectively combines the temporal characteristics of pig feature points, and efficiently recognizes the behavior of pigs.
[0122] Example 2
[0123] In order to verify the final effect of the pig behavior recognition method based on feature point detection, the experiment of this embodiment was carried out on a server with Ubuntu 24.04LTS operating system, Intel Core i7-13700KF CPU, and Nvidia GeForce RTX4090 graphics card. CUDA 12.0 was configured at the same time, and the Pytorch 2.1.0 deep learning framework was used to write Python programs based on Python3.9.
[0124] The proposed model is comprehensively evaluated using eight indicators, including precision (P), recall (R), average precision (AP), model parameter, Giga floating point of operations (GFLOPs), average precision (AP), F1 score, macro average, and weighted average. The calculation formulas for each indicator are as follows:
[0125]
[0126] Where, T P 、F P and F NThey represent the number of correctly predicted pig feature points, the number of non-pig feature points predicted as pig feature points, and the number of pig feature points incorrectly predicted as non-pig feature points. AP is the average precision, which is the area under the PR curve composed of precision and recall. d i is the Euclidean distance between each true feature point and the predicted feature point, v i is the feature point visibility mark, δ represents the normalization factor of the feature point, which is obtained by calculating the standard deviation of all feature points, s is the scale of the target, and k i is a constant for each key point; P represents precision, R represents recall, N represents the number of categories, i represents the index of the category, Mi represents the index of the i-th category (including P, R, F1 score), n i represents the number of samples in the i-th category, and T is defined as the sum of the number of samples in all categories.
[0127] Reference Fig. 9 The diagram shows the comparison of the loss changes of the original YOLOv8-Pose model, the YOLOv8-Pose model using the EIoU loss function, and the YOLO-ASF-P2 model proposed in this embodiment during the training process. Fig. 9 It can be seen that with the increase in the number of training iterations, the loss values of the three models gradually decrease, and they all tend to converge around the 275th round; at the same time, starting from around the 30th round, the loss of the two models using the EIoU loss function is lower than that of the original model until they tend to converge.
[0128] Furthermore, this embodiment designed a comparative experiment to verify the performance of the YOLO-ASF-P2 model. The experiments were not configured with the pre-trained weights provided by the YOLO official. The model iteration cycle was 300 rounds, the batch size was 32, the initial learning rate was 0.01, and the SGD optimizer was used for iterative optimization during model training. The results are shown in Table 1. As can be seen from Table 1, compared with YOLOv5-Pose, YOLOv7-Pose and YOLOv8-Pose, the recall rate of YOLO-ASF-P2 increased by 1.2, 3.5 and 2 percentage points respectively, and the AP 50~95 The YOLO-ASF-P2 model has a large comprehensive advantage and can meet the needs of accurate and efficient detection of pig feature points. 50~95 The OKS threshold is set between 0.5 and 0.95, and the step size is set to 0.05 under the average accuracy of 10 thresholds.
[0129] Table 1: Comparative experimental results of different detection models.
[0130]
[0131] In order to verify the target detection performance of the improved YOLOv8-Pose model, an ablation experiment was designed. The experimental results are shown in Table 2. As can be seen from Table 2, compared with the model before the improvement, the detection accuracy of the model after the introduction of the ASF architecture is improved by 0.3 percentage points, and the number of floating-point operations is increased by 5.7%, but the recall rate and AP are 50~95 The number of parameters slightly increased. After combining the P2 detection layer information, the detection accuracy of the model increased by 0.3 percentage points, AP 50~95 The number of floating-point operations increased by 1.1 percentage points, the number of floating-point operations increased by 34.9%, the number of model parameters decreased by 3.5%, but the recall rate decreased slightly. The increase in the number of floating-point operations is because the model combines more feature information of the target; the AP of the model after using the EIoU loss function is 50~95 The YOLO-ASF-P2 model after the fusion of the three models has an improvement of 1 percentage point in accuracy, 2 percentage points in recall, and AP 50~95 It increased by 1 percentage point, the number of floating-point operations increased by 31.5%, the number of parameters was only 18.4M, which was 17.5% lower than the original model. It has the best detection performance and is more lightweight.
[0132] Table 2: Ablation experiment results.
[0133]
[0134] Fig.10 This is a visual comparison of the detection results of the YOLO-ASF-P2 model and the YOLOv8-Pose model using Grad-CAM. The schematic boxes in the pictures of Group A and Group B in the figure show the detection of the model when the body has a significant scale change due to the pig being located at the edge of the picture. Fig.10 It can be seen that the YOLO-ASF-P2 model can effectively focus on the feature points of the pig, make full use of the detailed feature information of small targets provided by the P2 detection layer, and its ability to fuse multi-scale feature information is better than the original model; at the same time, the heat map shows that YOLO-ASF-P2 has a more complete coverage of the pig's body and the model is more robust.
[0135] Analysis of pig behavior recognition results:
[0136] The pig behavior recognition model CNN-Bi-GRU was trained using the RMSprop optimizer, StepLR learning rate scheduler and cross entropy loss function, with 80 training rounds. The recognition results of the model in the self-built pig behavior dataset are shown in Table 3. As can be seen from Table 3, the macro-average and weighted average results of the proposed model's recognition accuracy, recall rate and F1 score for the three behaviors of sitting, standing and lying of pigs are all over 96%, and the model performance is stable. Among them, the recognition effect of pig lying behavior is the worst, which is caused by the occlusion of feature points when pigs are lying.
[0137] Table 3: Pig behavior recognition results.
[0138]
[0139] In order to further verify the performance of the pig behavior recognition model proposed in this embodiment, a comparative experiment was designed. The recognition results of each model for the three behaviors of sitting, standing and lying of pigs in the self-built pig behavior data set are shown in Table 4. As can be seen from Table 4, the model with CNN structure captures the local dependency of time series data through convolution operation, and has higher average accuracy. The CNN-Bi-GRU model with attention mechanism dynamically adjusts the focus of the model by weighted integration of pig behavior information at each moment in the time series, thereby improving the recognition accuracy of the model.
[0140] Table 4: Comparative experimental results of different recognition models.
[0141]
[0142] This embodiment proposes a pig feature point detection model YOLO-ASF-P2 based on the improved YOLOv8-Pose model, which effectively addresses the problem of difficulty in feature point detection due to obvious scale changes of feature points during the daily activities of pigs, achieves high-precision recognition of pig feature points, and optimizes the pig feature extraction method; on the basis of feature point detection, in order to more accurately identify the behavior of pigs, a pig behavior recognition model CNN-Bi-GRU is proposed in combination with time domain information, which achieves high-precision recognition of the three behaviors of pigs: sitting, standing, and lying.
[0143] The pig feature point detection model YOLO-ASF-P2 achieves high-precision detection of pig feature points by integrating multi-scale feature information, focusing on local feature details, refining small target spatial positioning information, and improving the loss function. It has been verified that YOLO-ASF-P2 has high detection performance in terms of precision, recall, and average precision (AP 50~95) and floating-point operations increased by 1 percentage point, 2 percentage points, 1 percentage point and 31.5% respectively compared with the previous ones, and the number of model parameters decreased by 17.5% to only 18.4M; compared with YOLOv5-Pose and YOLOv7-Pose, the recall rate increased by 1.2 percentage points and 3.5 percentage points respectively, and the average precision (AP 50~95 ) increased by 0.8 percentage points and 1.2 percentage points respectively, and the number of floating-point operations increased by 31.5% and 49% respectively. The model has good performance, strong multi-scale feature fusion capabilities and is lightweight. It is suitable for deployment in resource-constrained environments and can provide a technical reference for accurate detection of pig feature points. The pig behavior recognition model CNN-Bi-GRU significantly improves the accuracy of pig behavior recognition by capturing local pig behavior characteristics and combining the attention mechanism to dynamically focus on the features of important time steps. It has been verified that the average recognition accuracy of the proposed model for the three behaviors of sitting, standing and lying of pigs in the self-built data set is 96%. The recognition performance is good and can effectively analyze the feature point information of pigs based on time series, thereby identifying the behavior of pigs.
[0144] It should be appreciated that embodiments of the present invention may be implemented or enforced by computer hardware, a combination of hardware and software, or by computer instructions stored in a non-transitory computer-readable memory. The method may be implemented in a computer program using standard programming techniques - including a non-transitory computer-readable storage medium configured with a computer program, wherein the storage medium so configured causes the computer to operate in a specific and predefined manner - according to the methods and drawings described in the specific embodiments. Each program may be implemented in a high-level procedural or object-oriented programming language to communicate with a computer system. However, if desired, the program may be implemented in an assembly or machine language. In any case, the language may be a compiled or interpreted language. In addition, the program may be run on a programmed ASIC for this purpose.
[0145] In addition, the operations of the process described in this embodiment may be performed in any suitable order, unless otherwise indicated in this embodiment or otherwise clearly contradicted by the context. The process described in this embodiment (or variations and / or combinations thereof) may be performed under the control of one or more computer systems configured with executable instructions, and may be implemented as a code (e.g., executable instructions, one or more computer programs, or one or more applications) executed jointly on one or more processors, by hardware or a combination thereof. The computer program includes a plurality of instructions that may be executed by one or more processors.
[0146] Further, the method can be implemented in any type of computing platform that is operably connected to a suitable computer, including but not limited to a personal computer, a minicomputer, a mainframe, a workstation, a network or distributed computing environment, a separate or integrated computer platform, or in communication with a charged particle tool or other imaging device, etc. Aspects of the present invention can be implemented in machine-readable code stored on a non-transitory storage medium or device, whether removable or integrated into a computing platform, such as a hard disk, an optical read and / or write storage medium, a RAM, a ROM, etc., so that it can be read by a programmable computer, and when the storage medium or device is read by the computer, it can be used to configure and operate the computer to perform the process described herein. In addition, the machine-readable code, or part thereof, can be transmitted via a wired or wireless network. When such media includes instructions or programs that implement the steps described above in conjunction with a microprocessor or other data processor, the invention described in this embodiment includes these and other different types of non-transitory computer-readable storage media. When programmed according to the methods and techniques described in the present invention, the present invention also includes the computer itself. The computer program can be applied to input data to perform the functions described in this embodiment, thereby converting the input data to generate output data stored in a non-volatile memory. The output information can also be applied to one or more output devices such as a display. In a preferred embodiment of the present invention, the converted data represents a physical and tangible object, including a specific visual depiction of the physical and tangible object produced on a display.
[0147] As used in this application, the terms "component", "module", "system", etc. are intended to refer to a computer-related entity, which can be hardware, firmware, a combination of hardware and software, software, or software in operation. For example, a component can be, but is not limited to: a process running on a processor, a processor, an object, an executable file, a thread in execution, a program, and / or a computer. As an example, an application running on a computing device and the computing device can both be components. One or more components can exist in a process and / or thread in execution, and a component can be located in a computer and / or distributed between two or more computers. In addition, these components can be executed from various computer-readable media having various data structures thereon. These components can communicate in a local and / or remote process manner, such as according to a signal having one or more data packets (e.g., data from a component that interacts with another component in a local system, a distributed system, and / or interacts with other systems in a signal manner through a network such as the Internet).
[0148] It should also be understood that the present invention is described through implementation methods, and the embodiments are only clear and complete descriptions of the technical solutions proposed in the claims of the present invention, that is, explanations of the claims. Therefore, when judging whether the technical solutions recorded in the specification of the present invention are sufficiently disclosed, full consideration should be given to the core essence of the solutions defined by the claims. In the specification, there must be other technical problems that are not related to the core technical problems proposed in this embodiment. The corresponding technical features and technical solutions do not belong to the essence of this embodiment and are non-essential technical features. Therefore, they can be referred to as implicit disclosures. Those skilled in the art can fully implement them in combination with existing technologies and common knowledge. Therefore, there is no need to describe them in detail.
[0149] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A pig behavior recognition method based on feature point detection, characterized in that: The following steps are included: Construct pig feature point detection dataset and pig behavior recognition dataset; The Neck part of the original YOLOv8-Pose model was modified, and the detailed feature information of small targets provided by the P2 layer of the Backbone part of the original model was combined to introduce the ASF architecture. The ASF architecture integrated the scale feature fusion module, the triple feature encoding module, and the channel and position attention mechanism module, and optimized the target box loss function to establish the pig feature point detection model YOLO-ASF-P2. The established pig feature point detection model YOLO-ASF-P2 is used to extract the time series information of feature points of key parts of the pig; Combining the time series information of the feature points, a pig behavior recognition model CNN-Bi-GRU is constructed; The pig behavior recognition model CNN-Bi-GRU flexibly captures the pig feature point information and performs weighted processing through a bidirectional gated recurrent unit and an attention mechanism, effectively combines the temporal characteristics of the pig feature points, and efficiently recognizes the three behaviors of sitting, standing, and lying of the pigs.
2. The pig behavior recognition method based on feature point detection according to claim 1 is characterized in that: Based on the feature information at the P2 level, the step of fully fusing the multi-scale feature information through the scale feature fusion module includes: Use 1×1 convolution module to adjust the number of channels of P4 and P5 level feature maps to the number of channels of P3 level feature maps, and adjust the number of channels of P3 and P4 level feature maps to the number of channels of P2 level feature maps; Use the nearest neighbor interpolation method to resize the P4 and P5 level feature maps to the size of the P3 level feature map, and resize the P3 and P4 level feature maps to the size of the P2 level feature map; Add an additional depth dimension to the dimensions of each level of feature layer, changing it from a 3D tensor to a 4D tensor; Connect the 4D feature maps along the depth dimension to form a 3D feature map for subsequent convolution; Scale feature extraction is done using 3D convolution, 3D batch normalization, and SiLU activation function.
3. The pig behavior recognition method based on feature point detection according to claim 1 is characterized in that: The triple feature encoding module is used to adjust the number of channels and spatial resolution of the feature map, including the following steps: For large-size feature maps, convolution, batch normalization, and SiLU activation functions are used to operate them, so that the number of channels of the large-size feature maps becomes twice that of the input, and then a hybrid structure of maximum pooling and average pooling is used for operation; For small-sized feature maps, a convolution module is used to reduce the number of channels to half of the original number, and then the nearest neighbor interpolation method is used for upsampling. The feature map is filled with information from adjacent pixels. Finally, the large, medium, and small feature maps of the same dimension are convolved separately and output after being spliced in the channel dimension.
4. The pig behavior recognition method based on feature point detection according to claim 1 is characterized in that: The channel and position attention mechanism module integrates detailed feature information output from the scale feature fusion module and the triple feature encoding module, and also includes: The channel and position attention mechanism module includes a channel attention network and a position attention network. The channel attention network replaces global cross-channel interaction with local cross-channel interaction, and the position attention network enhances the network's perception of feature point positions by considering the spatial structure information of the feature map.
5. The pig behavior recognition method based on feature point detection according to claim 4 is characterized in that: The channel attention network includes the following processing steps, The input feature map is subjected to global average pooling, and the average values of each channel obtained by the 1×1 convolution layer are fused. The weights are normalized by the Sigmoid function, and the normalized weights are multiplied by the original input feature map channel by channel to finally obtain the weighted feature map. The size k of the convolution kernel is set by one-dimensional convolution and nonlinear mapping, which can more effectively capture cross-channel dependencies. The size k of the convolution kernel is proportional to the channel dimension C, which is an exponential multiple of 2. The relationship between k and the channel dimension C is as follows: C=α(k)=2 (γ.k+b) Where γ and b are scaling parameters that control the ratio of the size of the convolution kernel k to the channel dimension C, The expression of k can be obtained through the inverse function: In the formula, |·| odd It means taking the odd value of the nearest neighbor, γ is set to 2, and b is set to 1.
6. The method for identifying pig behavior based on feature point detection according to claim 5, characterized in that: The position attention network includes the following processing steps: The output of the channel attention mechanism is combined with the output of the scale feature fusion module as input to extract the important spatial information of the pig feature points. The input feature map is divided into two parts according to width and height, and average pooling is performed in the width and height directions of the feature map to retain the spatial structure information of the feature map, as follows: In the formula, p w and p h Represent the results after horizontal and vertical pooling respectively, W and H are the width and height of the input feature map respectively, and E(i,j) is the value of the input feature map at position (i,j); The results of horizontal pooling and vertical pooling are spliced in the channel dimension, and the spliced results are convolved to obtain the fused feature map, as shown in the following formula: P(a w ,a h )=Conv[Concat(p w ,p h )] In the formula, P(a w ,a h ) represents the output result of the convolution operation, Conv represents the convolution operation, and Concat represents the serial concatenation operation; The fused feature map is split into two feature maps in the channel dimension, representing the attention of width and height respectively, as shown in the following formula: S w =Spl it(a w ) S h =Sp l it(a h ) In the formula, S w and S h are the width and height after segmentation respectively; For S w and S h Apply the Sigma id activation function respectively to get the normalized attention weights.
7. The method for identifying pig behavior based on feature point detection according to claim 1, characterized in that: The target box loss function includes the following optimization steps: Replace the original loss function with the EIoU loss function, the formula is as follows: Where IoU is the intersection over union ratio between the real target box and the predicted target box, ρ 2 (b,b gt ) is the Euclidean distance between the center of the predicted target box and the center of the true target box, w and h are the width and height of the predicted target box, respectively. gt and h gt are the width and height of the real bounding box, w c and h c are the width and height of the minimum outer bounding box of the real target box and the predicted target box, respectively. is the diagonal distance of the minimum outer bounding box.
8. The method for pig behavior recognition based on feature point detection according to claim 1, characterized in that: The pig behavior recognition model CNN-Bi-GRU is constructed based on gated recurrent units, where the Bi-GRU unit consists of two independent GRUs, which process data forward and backward according to the time series respectively, and includes the following steps: First, the convolutional layer is used to extract the local features of the temporal feature point data; Then apply the Bi-GRU unit for time series modeling, and apply the attention mechanism to the output of the Bi-GRU unit to generate weighted output; Finally, the pig behavior category is output through the fully connected layer.
9. The pig behavior recognition method based on feature point detection according to claim 8 is characterized in that: The h in the Bi-GRU unit t is the output state, which is realized as follows: In the formula, and are the states of the forward hidden layer and the backward hidden layer at time t, and are the weights of the forward hidden layer and the backward hidden layer states, respectively, and b t is the bias term.
10. The pig behavior recognition method based on feature point detection according to claim 9 is characterized in that: The pig behavior recognition model CNN-Bi-GRU includes the following steps: During the forward propagation of information, the attention mechanism module in the pig behavior recognition model CNN-Bi-GRU weights the importance of each time step to capture the key information in the sequence; Perform a linear transformation on the input and apply the Softmax activation function to calculate the attention weight; Finally, the input and weight are multiplied element by element, and the weighted result is returned. The specific implementation is as follows: a=W·x+b a probs =Softmax(a) Output=x⊙a probs In the formula, x represents the output of the Bi-GRU unit, a represents the result after applying a linear transformation to the input, and a probs represents the obtained attention weight, and ⊙ represents element-wise multiplication.
Citation Information
Patent Citations
Pig behavior recognition method and device, electronic equipment and storage medium
CN112215107A
Method for detecting daily behaviors of group health-preserving pigs
CN113822185A
Live pig attitude tracking method based on edge calculation and improved yolk
CN115909481A
End-to-end multi-target broiler behavior recognition method fusing space-time attention mechanism
CN117333948A
Cited By
Sow uterine contraction behavior identification method based on machine vision
CN120877386A