A live pig behavior recognition method based on feature point detection

By improving the YOLOv8-Pose model and constructing the CNN-Bi-GRU model, the problems of complexity and redundancy in pig feature extraction were solved, achieving efficient pig behavior recognition and improving the accuracy of feature point detection and behavior recognition.

CN119693996BActive Publication Date: 2025-11-11ZHEJIANG FORESTRY UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411374698.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2025-11-11
Estimated Expiration
2044-09-29

AI Technical Summary

Technical Problem

Existing methods for pig behavior recognition suffer from problems such as complex feature extraction, easy acquisition of redundant feature information, and low feature extraction efficiency due to the non-rigid body shape and varied postures of pigs.

Method used

A pig feature point detection model, YOLO-ASF-P2, was constructed by modifying the Neck part of the YOLOv8-Pose model and combining the scale feature fusion module, triple feature encoding module, and channel position attention mechanism in the ASF architecture to optimize the target box loss function and establish a pig feature point detection model. A pig behavior recognition model, CNN-Bi-GRU, was constructed by combining the temporal information of pig feature points and using bidirectional gated recurrent units and attention mechanisms to capture pig feature point information.

Benefits of technology

It improves the accuracy and recall of pig feature point detection, and can effectively identify the three behaviors of pigs: sitting, standing and lying down, providing an efficient method for pig behavior recognition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119693996B_ABST
    Figure CN119693996B_ABST
Patent Text Reader

Abstract

This invention discloses 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; establishing a pig feature point detection model YOLO-ASF-P2; constructing a pig behavior recognition model CNN-Bi-GRU by combining the temporal information of the feature points; and the pig behavior recognition model CNN-Bi-GRU efficiently recognizing three behaviors of pigs: sitting, standing, and lying down. The beneficial effects of this invention are: firstly, the pig feature point detection model YOLO-ASF-P2 has a detection accuracy of 92.5%, a recall rate of 90%, an average precision (AP50-95) of 68.2%, 39.2 GFLOPs of floating-point operations, and 18.4M model parameters; secondly, the pig behavior recognition model CNN-Bi-GRU achieves an average recognition accuracy of 96% for the three behaviors of pigs (sitting, standing, and lying down). The proposed pig feature point detection model is highly accurate and lightweight, effectively addressing the challenge of accurate feature point detection due to the changing postures of pigs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of pig behavior recognition, and more particularly to a pig behavior recognition method based on feature point detection. Background Technology

[0002] With the rapid development of technologies such as machine vision and deep learning, the pig farming industry is now transforming towards intensification and intelligentization. Pig behavior reflects its health and welfare; by monitoring and analyzing pig behavior, diseases, stress responses, and other abnormalities can be detected in a timely manner, allowing for appropriate measures to improve the health and productivity of the herd. Traditional methods of manually monitoring pig behavior are time-consuming, labor-intensive, and susceptible to subjective human factors. Utilizing machine vision and deep learning technologies to monitor and analyze pig behavior provides a wealth of real-time and accurate pig information while protecting pig welfare, offering strong support for ensuring pig health and improving farming efficiency.

[0003] Existing methods for pig behavior recognition and analysis suffer from problems such as complex pig feature extraction methods and the easy acquisition of redundant feature information. Furthermore, the body feature information of pigs during daily activities reflects their behavioral state. In the process of extracting pig features, the non-rigid body shape and varied postures of pigs also lead to the complexity and low efficiency of existing pig feature extraction methods. Summary of the Invention

[0004] The purpose of this section is to outline some aspects of embodiments of the present invention and to briefly describe some preferred embodiments. Simplifications or omissions may be made in this section, as well as in the abstract and title of this application, to avoid obscuring the purpose of these documents; however, such simplifications or omissions should not be construed as limiting the scope of the invention.

[0005] In view of the aforementioned existing problems, the present invention is proposed.

[0006] Therefore, the technical problem solved by the present invention is to provide a method for recognizing pig behavior based on feature point detection.

[0007] To address the aforementioned technical problems, this invention provides the following technical solution: 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 detailed feature information of small targets provided by the P2 layer of the Backbone part of the original model, introducing the ASF architecture, which integrates a scale feature fusion module, a triple feature encoding module, and a channel and position attention mechanism module, and optimizes the target box loss function to establish a pig feature point detection model YOLO-ASF-P2; extracting the temporal information of feature points of key parts of the pig using the established pig feature point detection model YOLO-ASF-P2; constructing a pig behavior recognition model CNN-Bi-GRU based on the temporal information of the feature points; the pig behavior recognition model CNN-Bi-GRU flexibly captures and weights pig feature point information through bidirectional gated recurrent units and attention mechanisms, effectively combining the temporal features of pig feature points to efficiently recognize the three behaviors of pigs: sitting, standing, and lying down.

[0008] Preferably, the step of fully fusing multi-scale feature information based on P2-level feature information through the scale feature fusion module includes: using a 1×1 convolution module to adjust the number of channels in the P4 and P5 level feature maps to the number of channels in the P3 level feature maps, and adjusting the number of channels in the P3 and P4 feature levels to the number of channels in the P2 level feature maps; using nearest neighbor interpolation to adjust the size of the P4 and P5 level feature maps to the size of the P3 level feature maps, and adjusting the size of the P3 and P4 level feature maps to the size of the P2 level feature maps; 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; and using 3D convolution, 3D batch normalization, and the SiLU activation function to complete scale feature extraction.

[0009] Preferably, adjusting the number of channels and spatial resolution of the feature map using the triple feature encoding module includes the following steps: For large-size feature maps, convolution, batch normalization, and SiLU activation functions are used to double the number of channels in the input feature map, and then a hybrid structure of max pooling and average pooling is used for the operation; For small-size feature maps, the number of channels is reduced to half of the original number using the convolution module, and then upsampling is performed using nearest neighbor interpolation to fill the feature map with information from adjacent pixels. Finally, the three feature maps of the same dimension (large, medium, and small) are convolved separately and then concatenated along the channel dimension before being output.

[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 further 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 ability to perceive the position of feature points by considering the spatial structure information of the feature map.

[0011] Preferably, the channel attention network includes the following processing steps: performing global average pooling on the input feature map, fusing the average values ​​of each channel obtained from the 1×1 convolutional layer, normalizing the weights using the Sigmoid function, and multiplying the normalized weights with the original input feature map channel by channel to obtain the final weighted feature map. The size k of the convolutional kernel is set through a one-dimensional convolution and non-linear mapping relationship, which can more effectively capture cross-channel dependencies. The size k of the convolutional 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:

[0012] C=α(k=2 (γ.k+b)

[0013] In the formula, γ and b are scaling parameters that control the ratio of the convolution kernel size k to the channel dimension C, respectively. The expression for k can be obtained through the inverse function:

[0014]

[0015] In the formula, |·| odd This indicates taking the odd value of the nearest neighbor, with γ set to 2 and b set to 1.

[0016] Preferably, the location 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 to extract important spatial information of 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 preserve the spatial structure information of the feature map, as follows:

[0017]

[0018] In the formula, p w and p h Let W and 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 and vertical pooling are concatenated along the channel dimension, and a convolution operation is performed on the concatenated result to obtain the fused feature map, as shown in the following equation:

[0019] P(a w ,a h =Conv[Concat(p w ,p h )]

[0020] In the formula, P(a w ,a h () represents the output of the convolution operation, Conv represents the convolution operation, and Concat represents the concatenation operation; the fused feature map is divided into two feature maps along 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 These are the width and height after segmentation, respectively; for S w and S h The normalized attention weights are obtained by applying the Sigmoid activation function.

[0024] Preferably, the target box loss function includes the following optimization steps: replacing the original loss function with the EIoU loss function, as shown in the following formula:

[0025]

[0026] In the formula, IoU is the intersection-union ratio between the ground truth bounding box and the predicted bounding box, and ρ 2 (b,b gt ) is the Euclidean distance between the center of the predicted bounding box and the center of the ground truth bounding box, where w and h are the width and height of the predicted bounding box, respectively. gt and h gt These are the width and height of the true bounding box, respectively. c and h c These are the width and height of the smallest bounding boxes of the ground truth bounding box and the predicted bounding box, respectively. This is the diagonal distance of the smallest bounding box.

[0027] Preferably, the CNN-Bi-GRU pig behavior recognition model is constructed based on gated recurrent units. The Bi-GRU unit consists of two independent GRUs, which process data in the forward and reverse directions of the time series, respectively. The model includes the following steps: first, using convolutional layers to extract local features of time series feature point data; then, applying the Bi-GRU unit to perform time series modeling and applying an attention mechanism to the output of the Bi-GRU unit to generate a weighted output; finally, outputting the pig behavior category through a fully connected layer.

[0028] Preferably, h in the Bi-GRU unit t The output state is implemented as follows:

[0029]

[0030] In the formula, These represent the states of the forward hidden layer and the backward hidden layer at time t, respectively. b represents the weights of the forward and backward hidden layer states, respectively. t This is a bias term.

[0031] Preferably, the CNN-Bi-GRU pig behavior recognition model includes the following steps: during the forward propagation of information, the attention mechanism module in the CNN-Bi-GRU pig behavior recognition model weights the importance of each time step to capture key information in the sequence; a linear transformation is performed on the input, and the Softmax activation function is applied to calculate the attention weights; finally, the input and weights are multiplied element-wise to return the weighted result. The specific implementation is 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, and a represents the result after applying a linear transformation to the input. probs The value represents the attention weight obtained, and ⊙ represents element-wise multiplication.

[0036] The beneficial effects of this invention are as follows: First, the YOLO-ASF-P2 pig feature point detection model has a detection accuracy of 92.5%, a recall rate of 90%, an average precision (AP50-95) of 68.2%, a floating-point operation count of 39.2 GFLOPs, and a model parameter count of 18.4M. Second, the CNN-Bi-GRU pig behavior recognition model has an average recognition accuracy of 96% for the three behaviors of pigs: sitting, standing, and lying down. The proposed pig feature point detection model has high accuracy and is lightweight, effectively addressing the challenge of accurate feature point detection due to the changing postures of pigs. Third, the pig behavior recognition model, combined with the time-domain information of pig feature points, can effectively recognize the three behaviors of pigs: sitting, standing, and lying down, providing a new approach to pig behavior recognition. Attached Figure Description

[0037] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein:

[0038] Figure 1 This is a schematic diagram illustrating the annotation of pig feature points according to the present invention;

[0039] Figure 2 This is a schematic diagram illustrating the missing and occluded features of pig features as described in this invention.

[0040] Figure 3 This is a schematic diagram of the three behaviors of pigs described in this invention;

[0041] Figure 4 This is a schematic diagram of the YOLO-ASF-P2 model structure described in this invention;

[0042] Figure 5 This is a schematic diagram of the structure of the triple feature encoding module described in this invention;

[0043] Figure 6 This is a schematic diagram of the channel and position attention mechanism module described in this invention;

[0044] Figure 7 This is a schematic diagram of the GRU structure described in this invention;

[0045] Figure 8 This is a schematic diagram of the CNN-Bi-GRU model structure described in this invention;

[0046] Figure 9 This is a schematic diagram of the target box loss value variation curve according to the present invention;

[0047] Figure 10 This is a heatmap showing the detection performance of different models described in this invention. Detailed Implementation

[0048] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of the present invention.

[0049] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of the invention. Therefore, the 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 phrase "in one embodiment" appearing in different places in this specification does not necessarily refer to the same embodiment, nor is it a single or selective embodiment that is mutually exclusive with other embodiments.

[0051] This invention is described in detail with reference to the schematic diagrams. When detailing the embodiments of this invention, for ease of explanation, the cross-sectional views illustrating the device structure may be partially enlarged, not adhering to the usual scale. Furthermore, the schematic diagrams are merely examples and should not be construed as limiting the scope of protection of this invention. In actual fabrication, the three-dimensional spatial dimensions of length, width, and depth should be included.

[0052] Furthermore, in the description of this invention, it should be noted that the terms "upper," "lower," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. These terms are used solely for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. In addition, the terms "first," "second," or "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0053] Unless otherwise explicitly specified and limited, the terms "installation," "connection," and "joining" in this invention should be interpreted broadly. For example, they can refer to fixed connections, detachable connections, or integral connections; similarly, they can refer to mechanical connections, electrical connections, or direct connections, or indirect connections through an intermediate medium, or internal connections between two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0054] Example 1

[0055] The physical characteristics of pigs during their daily activities reflect their behavioral state. However, due to the non-rigid nature and variable postures of pigs, existing pig feature extraction methods are complex and inefficient. Existing pig behavior recognition and analysis methods suffer from complex feature extraction methods and the tendency to obtain redundant feature information. Therefore, this embodiment first improves the YOLOv8-Pose model, proposing the YOLO-ASF-P2 pig feature point detection model to extract feature point information from 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, detailed information of small-scale feature points is preserved, enhancing the model's ability to fuse multi-scale feature information. This significantly reduces the number of model parameters while improving the accuracy of pig feature point detection, effectively addressing the scale changes in feature points caused by pig movement and other states, and is easy to deploy. Then, based on feature point detection, a CNN-Bi-GRU pig behavior recognition model is constructed. By analyzing a large amount of temporal information of feature points during pig movement, effective recognition of three pig behaviors—sitting, standing, and lying down—is achieved. Specifically, this embodiment proposes a method for pig behavior recognition based on feature point detection, including the following steps:

[0056] S1: Construct a dataset for detecting pig feature points and a dataset for recognizing pig behavior;

[0057] S2: Modify the Neck part of the original YOLOv8-Pose model, combine the detailed feature information of small targets provided by the P2 layer of the Backbone part of the original model, introduce the ASF architecture, which integrates the scale feature fusion module, the triple feature encoding module and the channel and position attention mechanism module, and optimizes the target box loss function to establish the pig feature point detection model YOLO-ASF-P2.

[0058] S3: Extract the temporal information of feature points of key parts of pigs using the established pig feature point detection model YOLO-ASF-P2;

[0059] S4: Construct a CNN-Bi-GRU model for pig behavior recognition by combining the temporal information of the aforementioned feature points;

[0060] S5: The CNN-Bi-GRU pig behavior recognition model flexibly captures pig feature point information and performs weighted processing through bidirectional gated recurrent units and attention mechanisms, effectively combining the temporal features of pig feature points to efficiently identify the three behaviors of pigs: sitting, standing and lying down.

[0061] More specifically, in step S1, which involves constructing a pig feature point detection dataset and a pig behavior recognition dataset, this embodiment includes three parts: data collection, construction of the pig feature point detection dataset, and construction of the pig behavior dataset. The data collection method is as follows: pig data was collected from Zhejiang Qingzhu Agricultural and Animal Husbandry Co., Ltd. and Zhejiang Hangzhou Gaohong Pig Farm. The pig breed was Landrace, with approximately 7-10 pigs per pen. The pigsty was rectangular in shape and equipped with water troughs, feed troughs, and ventilation devices. To facilitate comprehensive data collection, Hikvision cameras were installed at multiple angles, including the top and sides of the pigsty, primarily collecting data during peak daytime pig activity periods (7:00 AM to 5:00 PM), resulting in 52 video clips and 1026 raw images.

[0062] The implementation of the pig feature point detection dataset is as follows:

[0063] The open-source data annotation tool X-AnyLabeling was used to annotate the bounding boxes and feature points of pigs. The bounding box information mainly includes the coordinates of the center point, as well as the width and height of the bounding box; the feature point information includes the coordinates of the point and its visibility. The pig feature point annotation is as follows: Figure 1 As shown, there are 14 key points in total, including the pig's nose, forehead, shoulders, body (usually the back), rump, tail, left foreleg, left forefoot tip, right foreleg, right forefoot tip, left hind leg, left hind foot tip, right hind leg, and right hind foot tip.

[0064] The feature point annotation rules are as follows: a) For feature points missing due to the pig's body parts leaving the camera frame, the missing feature points are not annotated, and their visibility is set to 0. Figure 2 As shown in the rectangle at the top right corner of the left image. b) For cases where pig feature points appear normally, label the feature points and set their visibility to 1. c) For cases where pig body parts are in the frame but not visible due to camera angle or social interaction, label the occluded feature points and note them as 2, such as... Figure 2 As shown in the rectangle at the bottom right corner of the image on the right.

[0065] To improve the generalization ability and detection accuracy of the pig feature point detection model, this embodiment uses a combination of methods for image data enhancement, including Gaussian noise, salt-and-pepper noise, image sharpening, pixel cutout, brightness adjustment, and image translation. After offline enhancement, a total of 3028 images were saved and divided into training, validation, and test sets in a 6:2:2 ratio to construct a pig feature point detection dataset.

[0066] The pig behavior dataset was constructed and implemented as follows:

[0067] To obtain continuous time-series data on pig behavior, the YOLOv8 model's tracking branch was first used to track pigs in the video. The pixels surrounding the target pig were differentiated from pixels in other areas of the image to extract images of the pig standing, sitting, and lying down behaviors. Figure 3 As shown in the figure. Then, the pig feature point detection model was used to obtain the time series feature point data of pigs. A total of 109,740 time series data of pig sitting, standing and lying down behaviors were saved. After deduplication and other preprocessing operations, the training set, validation set and test set were divided in a 6:2:2 ratio to construct the pig behavior recognition dataset.

[0068] Furthermore, the construction of the pig feature point detection model includes YOLOv8, a high-performance object detection model. It adopts the network structure design principles of the YOLO series models. YOLOv8-Pose is a branch of the YOLOv8 model designed for pose estimation tasks, primarily used to identify key feature points of the research object in an image, outputting the [x, y] coordinates and confidence score of each point, to detect and identify 17 key points of human joints.

[0069] During pig movement, joints are prone to blurring and distortion, resulting in smaller target feature points, making accurate detection difficult when directly applying the YOLOv8-Pose model. To improve the detection accuracy of pig feature points, the YOLOv8-Pose model is improved in this embodiment as follows.

[0070] First, the Neck part of the original model is modified. Combining the detailed feature information of small targets provided by the P2 layer of the Backbone part of the original model, an improved ASF architecture is introduced. In this architecture, the scale sequence feature fusion module (SSFF) can combine global or high-level semantic information from multi-scale feature maps, the triple feature encoding module (TFE) can capture the fine local details of small targets, and the integration of local and global feature information can generate more accurate target features. The channel and position attention mechanism (CPAM) can capture and refine the spatial localization information related to small targets, improving the model's localization accuracy. Then, four prediction heads are used to predict image features, generating the target category, bounding box coordinates, the location information of 14 feature points of the pig, and confidence scores. The structure of the improved pig feature point detection model YOLO-ASF-P2 is as follows: Figure 4As shown, the parts connected by red lines represent improvements. In the diagram, Stack represents modules that stack features at different scales, 3D Conv is a 3D convolutional layer using a 1x1x1 convolutional kernel, BN is batch normalization, SiLU is the activation function, Concat is the feature connection module, Bbox Loss and Cls Loss are the bounding box loss and classification loss, respectively, Split is the feature map segmentation module, Bottleneck is the depthwise convolutional module, and Conv2d is a single convolutional module.

[0071] Furthermore, in this embodiment, the Scale Feature Fusion (SSFF) module is used to process multi-scale information of feature maps at various levels in the image pyramid. This module applies a Gaussian kernel and nearest neighbor interpolation method to align multi-scale feature maps with different downsampling factors to the same resolution as the high-resolution feature maps, thereby fully extracting information from deep and shallow feature maps of the same dimension.

[0072] First, given the feature maps of detection layers P2, P3, P4, and P5, convolve them using Gaussian kernels with progressively increasing standard deviations, as shown in the formula:

[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 mid-pixel, u and v represent the Gaussian filter G. σ The position coordinates in the kernel window, G σ For a Gaussian filter, F σ It uses a two-dimensional Gaussian filter G with a standard deviation of σ. σ The result after smoothing the feature map, where x and y are the coordinates of pixels in the image.

[0076] As can be seen from equation (1), 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 P2 level feature information, the SSFF module is used to fully fuse multi-scale feature information to improve the model's detection performance for pig feature points. The specific implementation steps are as follows:

[0078] ① Using a 1×1 convolution module, the number of channels in the P4 and P5 level feature maps is adjusted to 256 (the number of channels in the P3 level feature map), and the number of channels in the P3 and P4 feature levels is adjusted to 128 (the number of channels in the P2 level feature map).

[0079] ② Use nearest neighbor interpolation to adjust the size of the P4 and P5 level feature maps to the size of the P3 level feature map, and adjust the size of the P3 and P4 level feature maps to the size of the P2 level feature map.

[0080] ③ Use the unsqueeze method to add an extra 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] Furthermore, in this embodiment, the Triple Feature Encoding (TFE) module is used to balance the detailed information of feature maps at different scales. This module, by adjusting the number of channels and spatial resolution of the feature maps, can prevent the model from losing key target features during feature fusion, thereby improving the model's detection performance. For large-sized feature maps, the TFE module operates on them using convolution, batch normalization, and the SiLU activation function, doubling the number of channels in the large-sized feature map compared to the input. By increasing the number of channels, the capacity of the feature map can be increased, thus capturing more feature patterns. Then, a hybrid structure of max pooling and average pooling is used to reduce the spatial dimension of the feature map and achieve translation invariance, enhancing the network's robustness to spatial changes in the input feature map. For small-sized feature maps, the convolution module is first used to reduce the number of channels to half of the original, reducing computational complexity while retaining important semantic information. Then, nearest neighbor interpolation is used for upsampling, using the information of neighboring pixels to fill the feature map, which helps prevent the loss of feature information of small targets. Finally, the three feature maps of the same dimension (large, medium, and small) are convolved separately and then concatenated along the channel dimension before being output. The structure of the TFE module is as follows: Figure 5 As shown in the figure. Large, Medium, and Small represent feature maps at three scales: large, medium, and small. C represents the number of channels, S represents the size of the feature map, ConvBNSiLU is the convolution module, MaxPooling is the max pooling module, Downsapling is the downsampling part, Add is the feature map addition operation, Nearest is the nearest neighbor interpolation module, Upsampling is the upsampling part, and Concat is the feature fusion operation.

[0084] To effectively extract important feature information contained in different channels of the feature map, a Channel and Position Attention (CPAM) mechanism is used to integrate detailed feature information from the outputs of the SSFF and TFE modules. CPAM consists of a channel attention network and a position attention network. The channel attention network replaces global cross-channel interactions with local cross-channel interactions, avoiding the computational complexity caused by inefficiently capturing dependencies between all channels. The position attention mechanism enhances the network's ability to perceive the location of feature points by considering the spatial structure information of the feature map. The structure of CPAM is as follows: Figure 6 As shown in the diagram, AvgPool represents the average pooling module, Conv1D represents a 1×1 convolutional layer, and Sigmoid is the activation function, the specific implementation of which is as follows:

[0085] ① The channel attention network performs global average pooling on the input feature map and merges the average values ​​of each channel obtained from the 1×1 convolutional layer. Then, it normalizes the weights using the sigmoid function and multiplies the normalized weights with the original input feature map channel by channel to obtain the final weighted feature map. The kernel size k is set through a one-dimensional convolution and non-linear mapping relationship, which can more effectively capture cross-channel dependencies. The kernel size k is proportional to the channel dimension C, which is an exponential multiple of 2. Therefore, the relationship between k and the channel dimension C is as follows:

[0086] C=α(k=2 (γ.k+b) (3)

[0087] In the formula, γ and b are scaling parameters that control the ratio of the kernel size k to the channel dimension C.

[0088] The expression for k can be obtained through the inverse function:

[0089]

[0090] In the formula, |·| odd This indicates taking the odd value of the nearest neighbor, with γ set to 2 and b set to 1.

[0091] ② The positional 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 positional 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 respectively to preserve the spatial structure information of the feature map. The specific calculation is as follows:

[0092]

[0093] In the formula, p w and p hLet W and H represent the results of horizontal and vertical pooling, respectively. W and H are the width and height of the input feature map, respectively. 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 along the channel dimension, and the concatenated result is then convolved to obtain the fused feature map, as shown in Equation (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 of the convolution operation, Conv represents the convolution operation, and Concat represents the concatenation operation.

[0097] ④ The fused feature map is divided into two feature maps along 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 These are the width and height after the segmentation, respectively.

[0101] ⑤ Regarding S w and S h The normalized attention weights are obtained by applying the Sigmoid activation function.

[0102] Furthermore, while the CIoU loss function used in the original YOLOv8-Pose model considered the overlapping area, center distance, and aspect ratio of the target boxes, its shape analysis of the target boxes was inaccurate. To improve detection accuracy, the original loss function was replaced with the EIoU loss function. EIoU considers the impact of overlapping area and center distance on the loss function, as well as the width and height of the target boxes, focusing not only on the overlapping areas between target boxes but also on other non-overlapping areas, thus improving target detection performance. The formula for the EIoU loss is as follows:

[0103]

[0104] In the formula, IoU is the intersection-union ratio between the ground truth bounding box and the predicted bounding box, and ρ 2 (b,b gt ) is the Euclidean distance between the center of the predicted bounding box and the center of the ground truth bounding box, where w and h are the width and height of the predicted bounding box, respectively. gt and h gt These are the width and height of the true bounding box, respectively. c and h c These are the width and height of the smallest bounding boxes of the ground truth bounding box and the predicted bounding box, respectively. This is the diagonal distance of the smallest bounding box.

[0105] Furthermore, the construction of the CNN-Bi-GRU model for pig behavior recognition involves using a recurrent neural network (RNN), a type of neural network specifically designed for processing sequential data. During backpropagation, RNNs suffer from vanishing or exploding gradients, leading to short-term memory issues. GRU (gated recurrent unit) is a variant of RNN that introduces a gating mechanism to control the flow of information. It only requires updating and resetting gates and uses hidden states to pass information, resulting in a simple structure that effectively solves the short-term memory problem, enabling 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 Let z be the model input, historical candidate state, and hidden state at time t. t This represents the update gate, used to control the weights of historical states and current input information, r. t This represents the reset gate, used to reset the model's information in the current state, where σ is the sigmoid function.

[0106] The GRU implementation 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] In the formula, W z W r and W h This is the parameter matrix obtained from the backpropagation of the neural network.

[0111] To efficiently identify pig behavior by combining time-domain feature information, a CNN-Bi-GRU pig behavior recognition model was constructed based on gated recurrent units. The Bi-GRU (bidirectional gated recurrent unit) consists of two independent GRUs, processing data in the forward and backward directions of the time series, respectively. This bidirectional structure allows the Bi-GRU unit to simultaneously capture both forward and backward information from the sequence data, thereby improving the model's ability to understand the context. The model first uses convolutional layers to extract local features from the time-series feature point data, then applies the Bi-GRU unit for time-series modeling, and applies an attention mechanism to the output of the Bi-GRU unit to generate a weighted output. Finally, a fully connected layer outputs the pig behavior category. 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 that implements 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 The output state is implemented as follows:

[0113]

[0114]

[0115] In the formula, These represent the states of the forward hidden layer and the backward hidden layer at time t, respectively. b represents the weights of the forward and backward hidden layer states, respectively. t This is a bias term.

[0116] During the forward propagation of information, the AttentionBlock attention mechanism module in CNN-Bi-GRU can weight the importance of each time step, thereby better capturing key information in the sequence. It first performs a linear transformation on the input, then applies the Softmax activation function to calculate the attention weights, and finally multiplies the input and weights element-wise to return 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, and a represents the result after applying a linear transformation to the input. probs The value represents the attention weight obtained, and ⊙ represents element-wise multiplication.

[0121] The proposed feature point detection-based pig behavior recognition method utilizes YOLO-ASF-P2 combined with the high-resolution feature maps of the P2 layer in the YOLOv8-Pose backbone network to provide more target features. A scale feature fusion module aligns feature maps at different scales, enhancing the model's ability to fuse multi-scale feature information. Secondly, a triple feature encoding module balances the details of multi-scale feature information, preventing the model from losing target features. Finally, channel and position attention mechanisms capture the spatial information of feature points, accurately detecting pig feature points. CNN-Bi-GRU flexibly captures and weights pig feature point information through bidirectional gated recurrent units and attention mechanisms, effectively combining the temporal features of pig feature points for efficient pig behavior recognition.

[0122] Example 2

[0123] To verify the final effect of the feature point detection-based pig behavior recognition method, the experiment in this embodiment was conducted 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, and Python programs were written based on Python 3.9 using the PyTorch 2.1.0 deep learning framework.

[0124] The proposed model is comprehensively evaluated using eight metrics: precision (P), recall (R), average precision (AP), number of model parameters, giga floating-point operations (GFLOPs), F1 score, macro average, and weighted average. The formulas for each metric are as follows:

[0125]

[0126] In the formula, T P F P and F Nd represents the number of correctly predicted hog feature points, the number of non-hog feature points predicted as hog feature points, and the number of incorrectly predicted hog feature points as non-hog feature points, respectively. AP is the mean precision, which is the area under the PR curve formed by precision and recall; i It is the Euclidean distance between each ground truth feature point and each predicted feature point, v i This is the visibility marker for feature points, where δ represents the normalization factor for the feature points. This factor is obtained by calculating the standard deviation of all feature points, s is the target scale, and k... i These are constants for each keypoint; P represents precision, R represents recall, N represents the number of classes, i represents the index of the class, Mi represents the metrics for the i-th class (including P, R, and F1 score), and n... i Let T represent the number of samples in class i, and T be defined as the sum of the number of samples in all classes.

[0127] Reference Figure 9 The diagram illustrates and compares the loss changes during training 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. Figure 9 It can be seen that as the number of training iterations increases, 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 two models that used the EIoU loss function had lower losses than the original models, until they tended to converge.

[0128] Furthermore, to verify the performance of the YOLO-ASF-P2 model, a comparative experiment was designed in this embodiment. None of the experiments used the pre-trained weights provided by YOLO. The model iteration cycle was 300 rounds, the batch size was 32, and the initial learning rate was 0.01. 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 to YOLOv5-Pose, YOLOv7-Pose, and YOLOv8-Pose, the recall rate of YOLO-ASF-P2 improved by 1.2, 3.5, and 2 percentage points, respectively, and the AP... 50~95 The accuracy rates were improved by 0.8, 1.2, and 1 percentage points respectively. The parameter count was second only to YOLOv5-Pose at only 18.4M, and the number of floating-point operations was increased by 31.5%, 49%, and 31.5% respectively. In summary, the YOLO-ASF-P2 model has significant overall advantages and can meet the requirements for accurate and efficient feature point detection in pigs. 50~95 Set the OKS threshold between 0.5 and 0.95, with a step size of 0.05 for the average accuracy of 10 thresholds.

[0129] Table 1: Comparison of experimental results for different detection models.

[0130]

[0131] To verify the target detection performance of the improved YOLOv8-Pose model, an ablation experiment was designed, and the results are shown in Table 2. As can be seen from Table 2, compared to the original model, the introduction of the ASF architecture improved the detection accuracy by 0.3 percentage points and the number of floating-point operations by 5.7%, but the recall and AP remained relatively stable. 50~95 Slightly decreased, with a slight increase in the number of parameters; after incorporating information from the P2 detection layer, the model's detection accuracy improved by 0.3 percentage points, AP 50~95 The AP ratio improved by 1.1 percentage points, the number of floating-point operations increased by 34.9%, and the number of model parameters decreased by 3.5%, but the recall rate slightly decreased. The increase in the number of floating-point operations is because the model incorporates more feature information of the target. After using the EIoU loss function, the AP ratio of the model improved. 50~95 The accuracy improved by 0.2 percentage points, but the precision and recall decreased slightly, while the number of parameters and floating-point operations remained unchanged; the YOLO-ASF-P2 model after the fusion of the three improved the precision by 1 percentage point and the recall by 2 percentage points, AP 50~95 It improved by 1 percentage point, the number of floating-point operations was reduced by 31.5%, the number of parameters was only 18.4M, which is 17.5% lower than the original model. It has the best detection performance and is more lightweight.

[0132] Table 2: Ablation test results.

[0133]

[0134] Figure 10 This image presents a visual comparison of the detection performance of the YOLO-ASF-P2 and YOLOv8-Pose models using Grad-CAM. The bounding boxes in groups A and B illustrate the model's detection performance when significant scale changes occur due to the pigs being located at the edges of the images. Figure 10 It can be seen that the YOLO-ASF-P2 model can effectively focus on the feature points of pigs, making 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 comprehensive coverage of the pig body and the model is more robust.

[0135] Analysis of pig behavior recognition results:

[0136] The CNN-Bi-GRU model for pig behavior recognition was trained using the RMSprop optimizer, StepLR learning rate scheduler, and cross-entropy loss function for 80 training epochs. The recognition results of the model on a self-built pig behavior dataset are shown in Table 3. As shown in Table 3, the proposed model achieves over 96% accuracy, recall, and macro-average and weighted average F1 scores for the three pig behaviors of sitting, standing, and lying down, demonstrating stable performance. The recognition performance for lying down was the worst, likely due to feature point occlusion during this process.

[0137] Table 3: Results of pig behavior identification.

[0138]

[0139] To further verify the performance of the pig behavior recognition model proposed in this embodiment, a comparative experiment was designed. Table 4 shows the recognition results of each model for the three behaviors of pigs—sitting, standing, and lying down—in a self-built pig behavior dataset. As shown in Table 4, the model incorporating a CNN structure captures the local dependencies of time-series data through convolutional operations, resulting in higher average accuracy. The CNN-Bi-GRU model, which integrates an attention mechanism, dynamically adjusts the model's focus by weightedly integrating pig behavior information from each time step in the time series, thereby improving the model's recognition accuracy.

[0140] Table 4: Comparison of experimental results for different recognition models.

[0141]

[0142] This embodiment proposes a pig feature point detection model, YOLO-ASF-P2, based on the improved YOLOv8-Pose model. This model effectively addresses the challenge of feature point detection caused by significant scale changes in feature points during pigs' daily activities, achieving high-precision recognition of pig feature points and optimizing the pig feature extraction method. Building upon feature point detection, a pig behavior recognition model, CNN-Bi-GRU, is proposed, incorporating time-domain information to more accurately identify pig behavior. This model achieves high-precision recognition of three pig behaviors: sitting, standing, and lying down.

[0143] The YOLO-ASF-P2 model for detecting pig feature points achieves high-precision detection by fusing multi-scale feature information, focusing on local feature details, refining the spatial localization information of small targets, and improving the loss function. Verification shows that YOLO-ASF-P2 performs well in detecting pig feature points in terms of precision, recall, and average precision (AP). 50~95Compared to the previous version, the recall rate improved by 1 percentage point, 2 percentage points, 1 percentage point, and 31.5% respectively, while the number of model parameters decreased by 17.5% to only 18.4M. Compared to YOLOv5-Pose and YOLOv7-Pose, the recall rate improved by 1.2 percentage points and 3.5 percentage points respectively, and the average precision (AP) improved. 50~95 The accuracy of pig behavior recognition was improved by 0.8 and 1.2 percentage points respectively, and the number of floating-point operations was reduced by 31.5% and 49% respectively. The model exhibits good performance, strong multi-scale feature fusion capability, and is lightweight, making it suitable for deployment in resource-constrained environments. It can provide a technical reference for accurate detection of pig feature points. The CNN-Bi-GRU pig behavior recognition model significantly improves the accuracy of pig behavior recognition by capturing local pig behavior features and dynamically focusing on features at important time steps using an attention mechanism. Validation showed that the proposed model achieved an average recognition accuracy of 96% for sitting, standing, and lying behaviors of pigs on a self-built dataset, demonstrating good recognition performance and effectively analyzing time-series-based pig feature point information to identify pig behavior.

[0144] It should be recognized that embodiments of the present invention can be implemented or carried out by computer hardware, a combination of hardware and software, or by computer instructions stored in a non-transitory computer-readable storage medium. The method can be implemented using standard programming techniques—including a non-transitory computer-readable storage medium configured with a computer program, wherein such a storage medium causes the computer to operate in a specific and predefined manner—according to the methods and drawings described in the specific embodiments. Each program can be implemented in a high-level procedural or object-oriented programming language to communicate with the computer system. However, if desired, the program can be implemented in assembly or machine language. In any case, the language can be a compiled or interpreted language. Furthermore, for this purpose, the program can run on a programmed application-specific integrated circuit (ASIC).

[0145] Furthermore, the procedures described in this embodiment can be performed in any suitable order unless otherwise indicated by this embodiment or clearly contradicted by the context. The procedures (or variations and / or combinations thereof) described in this embodiment can be executed under the control of one or more computer systems configured with executable instructions, and can be implemented by hardware or a combination thereof as code (e.g., executable instructions, one or more computer programs, or one or more applications) that commonly executes on one or more processors. The computer program includes a plurality of instructions executable by one or more processors.

[0146] Furthermore, the method can be implemented in any suitable type of computing platform, including but not limited to personal computers, minicomputers, mainframes, workstations, networked or distributed computing environments, standalone or integrated computer platforms, or in communication with charged particle tools or other imaging devices, etc. Aspects of the invention can be implemented as 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, optical read and / or write storage medium, RAM, ROM, etc., such 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 processes described herein. Furthermore, the machine-readable code, or portions thereof, can be transmitted via wired or wireless networks. The invention described in this embodiment includes these and other different types of non-transitory computer-readable storage media when such media comprises instructions or programs that implement the steps described above in conjunction with a microprocessor or other data processor. When programmed according to the methods and techniques described in this invention, the invention also includes the computer itself. A computer program can be applied to input data to perform the functions described in this embodiment, thereby transforming the input data to generate output data stored in 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 invention, the converted data represents physical and tangible objects, including specific visual depictions of physical and tangible objects generated on a display.

[0147] As used herein, the terms “component,” “module,” “system,” etc., are intended to refer to a computer-related entity, which may be hardware, firmware, a combination of hardware and software, software, or running software. For example, a component may be, but is not limited to, a process running on a processor, a processor, an object, an executable file, a running thread, a program, and / or a computer. As an example, an application running on a computing device and the computing device itself can both be components. One or more components may reside in a running process and / or thread, and components may be located in a single computer and / or distributed among two or more computers. Furthermore, these components are capable of execution from various computer-readable media having various data structures thereon. These components may communicate locally and / or remotely via signals, such as based on one or more data packets (e.g., data from a component that interacts with a local system, another component in a distributed system, and / or signals that interact with other systems via a network such as the Internet).

[0148] It should also be understood that the present invention is described through embodiments, 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, the purpose and core essence of the solutions defined by the claims should be fully considered. There are necessarily other technical problems in the specification that are unrelated to the core technical problem solved by this embodiment. The corresponding technical features and technical solutions are not included in the essence of this embodiment and are non-essential technical features. Therefore, the implicit disclosure can be referred to. Those skilled in the art can fully implement them by combining existing technology 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 and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A method for recognizing pig behavior based on feature point detection, characterized in that: Includes the following steps, Construct a dataset for pig feature point detection and a dataset for pig behavior recognition; The Neck part of the original YOLOv8-Pose 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 the ASF architecture. The ASF architecture integrates the scale feature fusion module, the triple feature encoding module, and the channel and position attention mechanism module, and optimizes the target box loss function to establish the pig feature point detection model YOLO-ASF-P2. The established YOLO-ASF-P2 pig feature point detection model was used to extract the temporal information of feature points in key parts of pigs; A CNN-Bi-GRU model for pig behavior recognition is constructed by combining the temporal information of the aforementioned feature points; The CNN-Bi-GRU pig behavior recognition model flexibly captures and weights pig feature point information through bidirectional gated recurrent units and attention mechanisms, effectively combining the temporal features of pig feature points to efficiently recognize the three behaviors of pigs: sitting, standing, and lying down. The pig behavior recognition model CNN-Bi-GRU is based on gated recurrent units. The Bi-GRU unit consists of two independent GRUs, which process data in the forward and reverse directions of the time series, respectively. It includes the following steps: first, using convolutional layers to extract local features of time series feature point data. Then, Bi-GRU units are applied for time series modeling, and an attention mechanism is applied to the output of the Bi-GRU units to generate weighted outputs; finally, the pig behavior categories are output through a fully connected layer. h in the Bi-GRU unit t The output state is implemented as follows: In the formula, and These represent the states of the forward hidden layer and the backward hidden layer at time t, respectively. and b represents the weights of the forward and backward hidden layer states, respectively. t For bias terms; The CNN-Bi-GRU model for pig behavior recognition includes the following steps: During the forward propagation of information, the attention mechanism module in the CNN-Bi-GRU model weights the importance of each time step to capture key information in the sequence; a linear transformation is performed on the input, and the Softmax activation function is applied to calculate the attention weights; finally, the input and weights are multiplied element-wise to return the weighted result. 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, and a represents the result after applying a linear transformation to the input. probs represents the attention weights obtained, ⊙ represents element-wise multiplication, W represents linearly varying weights, and b represents linearly varying bias terms.

2. The method for pig behavior recognition based on feature point detection according to claim 1, characterized in that: Based on P2-level feature information, the steps of fully fusing multi-scale feature information through the scale feature fusion module include: A 1×1 convolution module is used to adjust the number of channels in the P4 and P5 level feature maps to the number of channels in the P3 level feature maps, and to adjust the number of channels in the P3 and P4 feature maps to the number of channels in the P2 level feature maps. The nearest neighbor interpolation method is used to adjust the size of the P4 and P5 level feature maps to the size of the P3 level feature maps, and the size of the P3 and P4 level feature maps to the size of the P2 level feature maps. Add an additional depth dimension to the dimension of each level of feature layer, changing it from a 3D tensor to a 4D tensor; The 4D feature maps are connected along the depth dimension to form a 3D feature map for subsequent convolution. Scale feature extraction was performed using 3D convolution, 3D batch normalization, and the SiLU activation function.

3. The method for pig behavior recognition based on feature point detection according to claim 1, characterized in that: Adjusting the number of channels and spatial resolution of the feature map using the triple feature encoding module includes the following steps: For large feature maps, we use convolution, batch normalization and SiLU activation function to double the number of channels in the input, and then use a hybrid structure of max pooling and average pooling. For small feature maps, a convolution module is used to reduce the number of channels to half of the original number. Then, the nearest neighbor interpolation method is used for upsampling. The information of adjacent pixels is used to fill the feature map. Finally, the three feature maps of the same dimension (large, medium, and small) are convolved separately and then concatenated along the channel dimension before being output.

4. The method for pig behavior recognition based on feature point detection according to claim 1, characterized in that: The channel and position attention mechanism module integrates detailed feature information 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 ability to perceive the position of feature points by considering the spatial structure information of the feature map.

5. The method for pig behavior recognition based on feature point detection according to claim 4, characterized in that: The channel attention network includes the following processing steps. The input feature map undergoes global average pooling, and the average values ​​of each channel obtained from the 1×1 convolutional layer are fused. The weights are normalized using the Sigmoid function, and then multiplied channel-by-channel with the original input feature map to obtain the final weighted feature map. The kernel size k is set through a one-dimensional convolution and non-linear mapping relationship to more effectively capture cross-channel dependencies. The kernel size k 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) In the formula, γ and b are scaling parameters that control the ratio of the convolution kernel size k to the channel dimension C, respectively. The expression for k can be obtained through the inverse function: In the formula, |·| odd This indicates taking the odd value of the nearest neighbor, with γ set to 2 and b set to 1.

6. The method for pig behavior recognition based on feature point detection according to claim 5, characterized in that: The location 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 important spatial information of pig feature points. The input feature map is divided into two parts according to width and height, and average pooling is performed on the width and height directions of the feature map respectively to preserve the spatial structure information of the feature map, as follows: In the formula, p w and p h Let W and H represent the results of horizontal and vertical pooling, respectively, where 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 concatenated along the channel dimension, and then a convolution operation is performed on the concatenated result 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 of the convolution operation, Conv represents the convolution operation, and Concat represents the concatenation operation; The fused feature map is split into two feature maps along the channel dimension, representing the width and height attention respectively, as shown in the following formula: S w =Split(a w ) S h =Split(a h ) In the formula, S w and S h These are the width and height after the segmentation, respectively; For S w and S h The normalized attention weights are obtained by applying the Sigmoid activation function.

7. The method for pig behavior recognition 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, as shown in the following formula: In the formula, IoU is the intersection-union ratio between the ground truth bounding box and the predicted bounding box, and ρ 2 (b,b gt ) is the Euclidean distance between the center of the predicted bounding box and the center of the ground truth bounding box, where w and h are the width and height of the predicted bounding box, respectively. gt and h gt These are the width and height of the true bounding box, respectively. c and h c These are the width and height of the smallest bounding boxes of the ground truth bounding box and the predicted bounding box, respectively. This is the diagonal distance of the smallest bounding box.

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