Pig breeding monitoring and behavior intervention method and system based on improved YOLOv11
By improving the YOLOv11 algorithm and computer vision technology, accurate identification and proactive management of pig behavior have been achieved, solving the problem of insufficient behavior recognition in existing technologies and improving the accuracy and efficiency of breeding management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SOUTH CHINA AGRICULTURAL UNIVERSITY
- Filing Date
- 2025-09-09
- Publication Date
- 2026-06-12
AI Technical Summary
Existing livestock monitoring technologies are insufficient in terms of the accuracy and real-time performance of behavioral recognition, making it difficult to effectively distinguish subtle changes in pig behavior, resulting in delayed responses to health problems. They also lack deep learning support, have inadequate data processing and analysis, and are unable to provide actionable management recommendations.
By employing an improved YOLOv11 algorithm combined with computer vision technology, real-time video data processing and feature extraction are used to identify pig behavior, construct a fighting warning and intervention mechanism, enhance recognition capabilities through multi-scale feature fusion and attention mechanisms, and construct a hierarchical response mechanism for behavioral intervention.
It enables accurate identification and proactive management of pig behavior, reduces the burden of manual inspection, lowers growth efficiency loss and disability rate caused by group conflict, and provides an immediate and low-stress management strategy.
Smart Images

Figure CN120954099B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent farming management technology, and more specifically, to a method and system for monitoring and intervening in pig farming behavior based on an improved YOLOv11. Background Technology
[0002] Currently, commonly used monitoring technologies in the livestock industry mainly include traditional systems based on video surveillance and simple behavioral analysis. These systems typically rely on manual observation and basic image processing techniques. While they can monitor the pigs' condition in real time, they have significant limitations in terms of the accuracy and real-time performance of behavioral recognition. Due to the lack of support from advanced algorithms such as deep learning, traditional systems often cannot effectively distinguish subtle changes in pig behavior, leading to delayed responses to health problems and abnormal behaviors, which in turn affects the scientific nature and efficiency of livestock management.
[0003] Furthermore, existing technologies have shortcomings in data processing and analysis. Many traditional systems can only record basic data, lacking in-depth analysis of behavioral patterns and failing to provide actionable management recommendations. This often leads farmers to rely on experience rather than data-driven decision-making when dealing with pig health issues, increasing management risks. Therefore, there is an urgent need for a new intelligent monitoring system that combines deep learning and real-time data analysis to improve the accuracy and efficiency of livestock management. Summary of the Invention
[0004] To address the aforementioned technical issues, this invention proposes a method and system for monitoring and intervening in pig farming based on an improved YOLOv11. By deeply integrating computer vision technology with an intelligent decision-making system, it achieves accurate identification and proactive management of pig behavior.
[0005] The first aspect of this invention provides a method for monitoring and intervening in pig farming based on an improved YOLOv11, comprising the following steps:
[0006] The system collects video data from inside the pigsty in real time using a camera, and transmits the video data to a processor for preprocessing to extract key video frames.
[0007] An improved YOLOv11 algorithm was used to construct a pig behavior detection model. The key video frames were imported into the pig behavior detection model for feature extraction. Features at different scales were aggregated and enhanced to generate feature maps. The detection head was used to achieve accurate recognition of pig behavior.
[0008] Based on the micro-behavioral characteristics of pigs, it is determined whether fighting will occur in the short term. If it is determined that fighting will occur, a fighting warning is triggered. When fighting is detected, an intervention mode is triggered, and intervention and adjustment methods are selected from the management decision database based on the pigs' behavioral status and environmental status.
[0009] The detection and identification results and intervention and adjustment records are stored in the database and fed back to the pig behavior detection model and management decision database for model and strategy updates.
[0010] In this solution, video data from inside the pigsty is collected in real time using a camera, and the video data is transmitted to a processor for preprocessing to extract key video frames. Specifically:
[0011] High-definition cameras deployed in the pigsty continuously capture real-time video streams of the pigsty at a fixed frame rate. The real-time video streams are then transmitted to the processor via a wireless network. After receiving the video streams, the processor performs noise reduction, illumination correction, and background separation to obtain pre-processed video streams.
[0012] The motion vectors of pigs in the video stream are obtained by optical flow calculation. The motion direction and speed are extracted as local features. Key motion regions in the video stream are obtained by spatiotemporal interest point detection. The dynamic changes of the pig's head and limbs are captured. Local motion features are generated based on the local features and the dynamic changes of the pig's head and limbs.
[0013] The local motion features are encoded, and the continuous motion data is discretized into semantic units. The encoded local motion features are mapped to a high-dimensional semantic space through an autoencoder network. The K-means clustering algorithm is used to cluster the feature vectors with semantic labels to generate an action semantic dictionary.
[0014] The similarity between the local motion features of the video stream and the cluster centers in the action semantic dictionary is calculated. Video frames with similarity higher than the threshold are selected as candidate key frames. Redundant frames are removed by combining temporal continuity analysis, and key video frames are extracted.
[0015] In this scheme, an improved YOLOv11 algorithm is used to construct a pig behavior detection model, specifically as follows:
[0016] The improved YOLOv11 algorithm is based on the CSPDarknet architecture, which combines fast spatial pyramid pooling and cross-stage local spatial attention as the backbone network. A multi-scale feature fusion module is used to construct the neck structure of the YOLOv11 algorithm. The improved YOLOv11 algorithm is constructed based on the backbone network, neck structure, detection head and optimized loss.
[0017] A pig behavior detection model was built based on the improved YOLOv11. The complex structure in the original C3k2 module was replaced with FasterBlock of FasterNet. In FasterBlock, partial convolution and two layers of standard convolution were used, and residual connections were made with the input to perform lightweight feature extraction.
[0018] Channel and spatial attention modules are embedded at the junction of the backbone network and the neck structure. Channel attention is used to adjust the feature channel weights, and spatial attention is used to enhance the target location information, so that the model focuses on the key areas of the pig.
[0019] Focal EIOU Loss is adopted as the regression loss function for bounding boxes. The absolute difference terms of width and height are introduced. Combined with the Focal Loss mechanism, higher loss weights are applied to occluded samples and small target samples, guiding the model to pay more attention to these difficult-to-detect targets.
[0020] Collect monitoring videos of pigsties, label the pig locations and behavior categories to construct a pig behavior dataset, pre-train the backbone network of the pig behavior detection model on a general object detection dataset, initialize the model parameters, fine-tune using the pig behavior dataset, and optimize the position regression and behavior classification of the detection heads.
[0021] In this scheme, the key video frames are imported into a pig behavior detection model for feature extraction. Features at different scales are aggregated and enhanced to generate a feature map. The feature map is then used to identify pig behavior. Specifically:
[0022] Key video frames containing significant behavioral information are imported into a pig behavior detection model. Low-level features and high-level semantic features are extracted in the backbone network through convolutional layers and C3k2-faster modules, and multi-scale feature maps are output.
[0023] By fusing feature maps of different scales through a fast spatial pyramid pooling module, further aggregating features using a cross-stage local spatial attention module, enhancing features with channel attention and spatial attention, and using a bidirectional feature pyramid network to achieve top-down and bottom-up feature fusion, an optimized feature map is obtained.
[0024] The detection head generates bounding box coordinates and behavior category probabilities based on the optimized feature map, matches the predicted bounding boxes with the action semantic dictionary, and determines the pig behavior category by combining the temporal context.
[0025] In this plan, the likelihood of pig fighting in the short term is determined based on the pigs' micro-behavioral characteristics. If this is predicted, a fighting warning is triggered, specifically as follows:
[0026] The micro-behavioral features of pigs in each frame are detected in real time using a pig behavior detection model. These micro-behavioral features include posture features, motion features, and interaction features. A sliding time window is constructed to extract the continuous behavioral sequence of pigs within the window.
[0027] A spatiotemporal feature encoder is constructed using 1D convolution and BiLSTM networks, and the contribution weights of each feature are calculated through a self-attention mechanism to obtain the encoded feature vector.
[0028] The feature vector is compared with the pre-defined pre-fighting behavior features in the pre-defined pre-fighting behavior library to obtain the matching weight. Based on the initial pattern weight set according to the pig behavior category in the continuous behavior sequence, the dynamic fighting risk is quantified using the matching weight and the initial pattern weight. If the cumulative fighting risk in the window is greater than the preset threshold, it is determined that a fight between pigs is about to occur.
[0029] Based on the accumulated struggle risk, a pre-set graded early warning mechanism is used to trigger graded struggle warnings in real time.
[0030] In this plan, when fighting behavior among pigs is detected, an intervention mode is triggered. Based on the pigs' behavioral state and the environmental state, intervention and adjustment methods are selected from the management decision database. Specifically:
[0031] When fighting behavior among pigs is detected, the conflict area is magnified by a high frame rate camera for visual verification to confirm whether actual physical contact has occurred. Temporal verification is used to check whether the fighting behavior continues for more than a threshold time, and group verification is used to analyze whether a chain reaction occurs among the surrounding pigs.
[0032] Based on the review results, the pig conflict level is classified, and the pig behavior status is generated by combining the pig behavior characteristics. At the same time, the current environmental parameters are obtained to generate the environmental status.
[0033] Obtain historical intervention examples that include voice and physical adjustments; analyze the intervention type, applicable scenarios, and priority based on each historical intervention example; store the results in a pre-built management decision library; and label each intervention example with matching features.
[0034] A behavior-intervention bipartite graph is constructed based on the current pig behavior status and intervention measures in the management decision database. Edge weights are constructed in the behavior-intervention bipartite graph based on the historical intervention success rate. The pigs are located in the behavior-intervention bipartite graph based on their current behavior status.
[0035] Starting from the location node, a random walk is performed. The probability of reaching each intervention node is calculated based on the edge weight. The walk ends when a physical intervention node is reached, and a walk path is generated. The intervention node with the highest visit frequency in the walk path is counted. If there are nodes with the same frequency, the intervention node with higher priority is selected, and the intervention adjustment method is output.
[0036] In this solution, the detection and identification results and intervention records are stored in a database and fed back to the pig behavior detection model and management decision database for model and strategy updates. Specifically:
[0037] The detection and identification results and intervention and adjustment records are structured to generate a detection result table and an intervention record table. The detection result table and intervention record table are periodically batch processed to merge multiple intervention records of the same event and to statistically analyze the behavioral frequency heat map of each pig house area.
[0038] Data augmentation was performed on the newly added pig fighting behavior samples, the backbone network of the pig behavior detection model was frozen, the classification weights of the detection heads were fine-tuned, incremental updates of the model were achieved, the weights of the pig prodromal behavior categories were recalculated based on the intervention effect rating, the time window was adjusted to be larger, and the short-term prediction accuracy was optimized.
[0039] Based on the evaluation of intervention effects, intervention records that meet the preset requirements are selected, and the corresponding combinations of pig behavioral characteristics are extracted to establish an efficient intervention model knowledge graph. Intervention measures with more than a preset threshold of consecutive failures are downgraded in priority.
[0040] The second part of this invention provides a pig farming monitoring and behavior intervention system based on an improved YOLOv11. The system includes: a data acquisition module, a data preprocessing module, a pig behavior detection module, a fight warning module, a behavior intervention module, and a data management module.
[0041] The data acquisition module collects video data from inside the pigsty in real time through a camera and transmits it to the processor via a wireless network.
[0042] The data preprocessing module transmits video data to the processor for preprocessing and extracts key video frames.
[0043] The pig behavior detection module uses an improved YOLOv11 algorithm to build a pig behavior detection model. The key video frames are imported into the pig behavior detection model for feature extraction. Features at different scales are aggregated and enhanced to generate a feature map. The feature map is then used to input the detection head to identify pig behavior.
[0044] The fighting warning module determines whether pig fighting will occur in the short term based on the pigs' micro-behavioral characteristics. If it determines that fighting will occur, it triggers a fighting warning.
[0045] When the behavior intervention module detects fighting behavior among pigs, it triggers an intervention mode and selects intervention and adjustment methods from the management decision database based on the pigs' behavior and environmental conditions.
[0046] The data management module stores the detection and identification results and intervention and adjustment records in the database, and feeds them back to the pig behavior detection model and management decision database for model and strategy updates.
[0047] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0048] This invention achieves accurate identification and proactive management of pig behavior by deeply integrating computer vision technology with an intelligent decision-making system. Employing a lightweight, improved YOLOv11 algorithm as the core detection engine, and through the introduction of attention mechanisms and feature fusion optimization, it significantly enhances the ability to identify micro-behaviors of pigs in complex farming environments, particularly demonstrating high sensitivity to conflict behaviors in group interactions. Its multi-scale feature extraction architecture effectively addresses real-world challenges such as pig occlusion and varied postures, ensuring comprehensive monitoring coverage from individual actions to group dynamics.
[0049] In terms of behavioral intervention, a tiered response mechanism was constructed, employing multimodal methods such as sound modulation, odor intervention, and physical devices to form a progressive management strategy. This primarily non-contact intervention approach ensures immediate results while minimizing stress on pigs. The system's unique dynamic risk assessment model can predict potential conflicts through temporal behavioral analysis, enabling a shift from passive response to proactive prevention. This invention represents a leap from manual observation to intelligent analysis in livestock monitoring, not only reducing the burden of manual inspections but also effectively lowering growth efficiency losses and disability rates caused by group conflicts. Attached Figure Description
[0050] To more clearly illustrate the technical solutions in the embodiments or examples of the present invention, the drawings used in the embodiments or examples 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 according to these drawings without creative effort.
[0051] Figure 1 A flowchart of a pig farming monitoring and behavioral intervention method based on an improved YOLOv11 is shown;
[0052] Figure 2 The flowchart illustrates the process of identifying pig behavior using a pig behavior detection model.
[0053] Figure 3 The flowchart of the algorithm using the improved YOLOv11 algorithm is shown;
[0054] Figure 4 A flowchart is shown showing the selection of intervention and regulation methods from a management decision database based on pig behavior and environmental conditions;
[0055] Figure 5 A block diagram of a pig farming monitoring and behavior intervention system based on the improved YOLOv11 is shown. Detailed Implementation
[0056] To better understand the above-mentioned objectives, features, and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0057] 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 therefore the scope of protection of the invention is not limited to the specific embodiments disclosed below.
[0058] Figure 1 A flowchart of a pig farming monitoring and behavioral intervention method based on the improved YOLOv11 is shown.
[0059] S102, real-time video data of the pigsty is collected by the camera and the video data is transmitted to the processor for preprocessing to extract key video frames;
[0060] S104, a pig behavior detection model is constructed using an improved YOLOv11 algorithm. The key video frames are imported into the pig behavior detection model for feature extraction. Features at different scales are aggregated and enhanced to generate a feature map. The feature map is then used to identify pig behavior.
[0061] S106. Based on the micro-behavioral characteristics of pigs, determine whether fighting behavior among pigs will occur in the short term. If it is determined that fighting will occur, trigger a fighting warning. When fighting behavior among pigs is detected, trigger the intervention mode and select intervention and adjustment methods from the management decision database based on the pigs' behavioral status and environmental status.
[0062] S108 stores the detection and identification results and intervention and adjustment records in the database, and feeds them back to the pig behavior detection model and management decision database for model and strategy updates.
[0063] It should be noted that high-definition cameras are deployed in the pigsty to ensure coverage of the main areas where the pigs are active. The high-definition cameras deployed in the pigsty continuously collect real-time video streams of the pigsty at a fixed frame rate. The real-time video streams are transmitted to the processor via a wireless network. After receiving the video stream, the processor performs noise reduction, illumination correction, and background separation to obtain a pre-processed video stream.
[0064] Dense optical flow computation is used to obtain the motion vectors of pigs in the video stream, and the motion direction and velocity are extracted as local features. Key motion regions in the video stream are identified using spatiotemporal interest point detection algorithms such as Harris3D, capturing the dynamic changes of the pig's head and limbs. Local motion features are generated based on these local features and the dynamic changes of the pig's head and limbs. A bag-of-words model is used to encode these local motion features, discretizing continuous motion data into semantic units. An autoencoder network maps the encoded local motion features to a high-dimensional semantic space, representing behavioral categories such as chasing, biting, and lying down. K-means clustering is used to cluster the feature vectors with semantic labels, with each cluster center representing a typical motion pattern, generating an action semantic dictionary. The similarity (e.g., cosine distance) between the local motion features of the video stream and the cluster centers in the action semantic dictionary is calculated. Video frames with similarity higher than a threshold are selected as candidate keyframes, and redundant frames are removed using temporal continuity analysis to extract key video frames.
[0065] Figure 2 A flowchart is shown for identifying pig behavior using a pig behavior detection model.
[0066] According to an embodiment of the present invention, the key video frames are imported into a pig behavior detection model for feature extraction, features at different scales are aggregated and enhanced to generate a feature map, and the feature map is used to identify pig behavior, specifically as follows:
[0067] S202: Key video frames containing significant behavioral information are obtained and imported into the pig behavior detection model. In the backbone network, shallow features and deep semantic features are extracted through convolutional layers and C3k2-faster modules, and multi-scale feature maps are output.
[0068] S204 uses a fast spatial pyramid pooling module to fuse feature maps of different scales, employs a cross-stage local spatial attention module to further aggregate features, uses channel attention and spatial attention for enhancement, and uses a bidirectional feature pyramid network to achieve top-down and bottom-up feature fusion to obtain optimized feature maps.
[0069] S206, the detection head generates bounding box coordinates and behavior category probabilities based on the optimized feature map, matches the predicted bounding boxes with the action semantic dictionary, and determines the pig behavior category by combining the temporal context.
[0070] It should be noted that convolutional layers and the C3k2-faster module extract low-level features such as edges and textures, and high-level semantic features such as limb pose and head orientation, outputting multi-scale feature maps to meet the detection needs of small, medium, and large targets. A CBAM module is embedded in the feature extraction stage, and channel attention calculates the weights of each channel, highlighting feature channels related to pig behavior, such as areas of vigorous movement. Spatial attention focuses on key spatial regions in the feature maps, such as the pig's head or contact areas. The SPPF (Fast Spatial Pyramid Pooling) module fuses feature maps of different scales, preserving multi-scale contextual information. The C2PSA (Cross-Stage Local Spatial Attention) module further aggregates features, enhancing the perception of small targets and occluded scenes. A Bidirectional Feature Pyramid Network (BiFPN) or similar structure is used to achieve top-down and bottom-up feature fusion, optimizing the coherence of behavioral features. The detection head generates prediction results based on the optimized feature maps, matches the predicted bounding boxes with the action semantic dictionary, and determines the final behavior category based on temporal context. For example, if high-speed movement and head contact are detected in multiple consecutive frames, it is determined to be fighting behavior.
[0071] To meet the need for real-time detection of fighting behavior in pigs on embedded devices, this paper proposes a lightweight detection algorithm based on YOLOv11 for this task. Figure 3 As shown, the C3k2 module is replaced with the more efficient C3k2-faster module to reduce the model's computational complexity; a spatial and channel joint attention mechanism (CBAM) is introduced to enhance the expressive power of key features and improve detection accuracy. To address the common problems of dense occlusion and imbalanced samples in pig fighting behavior, CIOU Loss is replaced with FocalEIOU Loss to further improve the model's detection performance in complex scenes.
[0072] The YOLOv11 algorithm's backbone network, based on the CSPDarknet architecture and incorporating fast spatial pyramid pooling and cross-stage local spatial attention modules, is responsible for extracting multi-scale features from the input image. A neck structure for the YOLOv11 algorithm is constructed using bidirectional feature pyramids, channel attention, and spatial attention to enhance feature fusion capabilities. The detection head outputs the position, category, and confidence score of the predicted bounding box for pig target detection and behavior classification. An improved YOLOv11 algorithm is constructed based on the backbone network, neck structure, detection head, and optimized loss. A pig behavior detection model is built using the improved YOLOv11 algorithm, replacing the complex structure in the original C3k2 module with FasterNet's FasterBlock to reduce the number of parameters. In FasterBlock, partial convolution and two layers of standard convolution are used, with residual connections to the input for lightweight feature extraction, improving computational efficiency while maintaining accuracy. Channel and spatial attention modules are embedded between the backbone network and the neck structure. Channel attention is used to adjust the feature channel weights, and spatial attention is used to enhance target location information, enabling the model to focus on key areas of the pig and alleviate the data imbalance problem. For the output of the detection head, Focal EIOU Loss is used as the regression loss function for the bounding box, introducing absolute difference terms for width and height to more accurately measure the deviation between the predicted box and the ground truth box. The penalty term for aspect ratio difference makes the predicted box closer to the ground truth box in shape. Combined with the Focal Loss mechanism, the training weights for occluded samples and small target samples are increased to alleviate the data imbalance problem.
[0073] A pig behavior dataset was constructed by collecting monitoring videos from pigsties and labeling pig locations with behavioral categories such as eating, lying down, and fighting. This dataset covers common abnormal behaviors like biting and chasing, as well as normal behaviors. Furthermore, methods such as random cropping, rotation, and brightness adjustment were used to expand the dataset, improving the model's generalization ability and simulating occlusion scenarios to enhance its robustness. The backbone network of the pig behavior detection model was pre-trained on a general object detection dataset, and the model parameters were initialized. Fine-tuning was then performed using the pig behavior dataset to optimize head position regression and behavior classification.
[0074] It should be noted that the pig behavior detection model detects the micro-behavioral features of pigs in each frame in real time. These micro-behavioral features include posture features, motion features, and interaction features. Posture features include head height, ear erection status, and tail wagging frequency. Motion features include sudden changes in speed and direction of movement. Interaction features include distance between pigs, body contact points, and contact duration. A sliding time window is constructed to extract continuous behavioral sequences of pigs within the window. A spatiotemporal feature encoder is constructed using 1D convolution and BiLSTM networks, and the contribution weights of each feature are calculated through a self-attention mechanism to obtain the encoded feature vector.
[0075] The feature vector is compared with the pre-defined pre-fighting behavior features in the pre-defined pre-fighting behavior library using cosine similarity to obtain matching weights. Based on the initial pattern weights set according to the pig behavior categories in the continuous behavior sequence, the dynamic fighting risk is quantified using the matching weights and the initial pattern weights. The dynamic fighting risk of all frames within the sliding window is weighted by time decay to obtain the cumulative fighting risk. If the cumulative fighting risk within the window is greater than a preset threshold, it is determined that a pig fight is about to occur. Based on the cumulative fighting risk, a preset graded early warning mechanism is used to trigger a graded fighting warning in real time.
[0076] According to an embodiment of the present invention, when fighting behavior among pigs is detected, an intervention mode is triggered, and an intervention and adjustment method is selected from the management decision database based on the pigs' behavioral state and the environmental state. Specifically:
[0077] S402: When pig fighting behavior is detected, the conflict area is magnified by a high frame rate camera for visual verification to confirm whether actual physical contact has occurred. A time-series verification is used to check whether the fighting behavior continues for more than a threshold time, and a group verification is used to analyze whether a chain reaction occurs among the surrounding pigs. Based on the verification results, the pig conflict level is classified, and the pig behavior status is generated by combining the pig behavior characteristics. At the same time, the current environmental parameters such as light intensity and pig density are acquired to generate the environmental status.
[0078] S404: Obtain historical intervention examples that include sound and physical adjustments, such as playing sudden noises, sow calls, and classical light music, as well as spraying maternal comfort pheromones and activating the patting device. Analyze the intervention type, applicable scenarios, and priority based on each historical intervention example, store it in the pre-built management decision library, and label each intervention with matching features.
[0079] S406, construct a behavior-intervention bipartite graph based on the current pig behavior status and intervention measures in the management decision database, construct edge weights in the behavior-intervention bipartite graph based on the historical intervention success rate, and locate the pig in the behavior-intervention bipartite graph based on the current pig behavior status;
[0080] S408: Start from the positioning node and perform a random walk. Calculate the probability of reaching each intervention node based on the edge weights. End the walk when the physical intervention node is reached, generate the walk path, and count the intervention node with the highest access frequency in the walk path. If there are nodes with the same frequency, select the intervention node with higher priority and output the intervention adjustment method.
[0081] It should be noted that the detection and identification results and intervention records are structured to generate detection result tables and intervention record tables. These tables undergo periodic batch processing, merging multiple intervention records for the same event, and generating heatmaps of behavioral frequency for each pigsty area. Data augmentation is performed on newly added pig fighting behavior samples, the backbone network of the pig behavior detection model is frozen, and the classification weights of the detection heads are fine-tuned. The validation set uses negative samples (normal behavior) from the past 7 days to prevent overfitting, enabling incremental model updates. Based on the intervention effect rating, the weights of pig precursor behaviors are recalculated, the time window is adjusted, and short-term prediction accuracy is optimized. Intervention records meeting preset requirements are selected based on the intervention effect evaluation, and corresponding pig behavioral feature combinations are extracted to establish an efficient intervention pattern knowledge graph. Intervention measures with more than a preset threshold of consecutive failures are downgraded in priority. By establishing a complete data loop, the system continuously accumulates behavioral samples and intervention records, using incremental learning to optimize algorithm parameters, thereby continuously improving identification accuracy and decision adaptability over time. The adaptive update mechanism of the management decision base ensures that the intervention strategy always maintains optimal matching with the current pig herd behavioral characteristics.
[0082] Figure 5 An architecture diagram of a pig farming monitoring and behavior intervention system based on an improved YOLOv11 is shown.
[0083] The second embodiment of the present invention provides a pig farming monitoring and behavior intervention system 5 based on an improved YOLOv11. The system includes: a data acquisition module 501, a data preprocessing module 502, a pig behavior detection module 503, a fight early warning module 504, a behavior intervention module 505, and a data management module 506.
[0084] The data acquisition module collects video data from inside the pigsty in real time through a camera and transmits it to the processor via a wireless network.
[0085] The data preprocessing module transmits video data to the processor for preprocessing and extracts key video frames.
[0086] The pig behavior detection module uses an improved YOLOv11 algorithm to build a pig behavior detection model. The key video frames are imported into the pig behavior detection model for feature extraction. Features at different scales are aggregated and enhanced to generate a feature map, which is then used to identify pig behavior.
[0087] The fighting warning module determines whether pig fighting will occur in the short term based on the pigs' micro-behavioral characteristics. If it determines that fighting will occur, it triggers a fighting warning.
[0088] When the behavior intervention module detects fighting behavior among pigs, it triggers an intervention mode and selects intervention and adjustment methods from the management decision database based on the pigs' behavior and environmental conditions.
[0089] The data management module stores the detection and identification results and intervention and adjustment records in the database, and feeds them back to the pig behavior detection model and management decision database for model and strategy updates.
[0090] The third embodiment of the present invention provides a computer-readable storage medium, which includes a program for a pig farming monitoring and behavior intervention method based on improved YOLOv11. When the program for the pig farming monitoring and behavior intervention method based on improved YOLOv11 is executed by a processor, it implements the steps of the pig farming monitoring and behavior intervention method based on improved YOLOv11.
[0091] In the several embodiments provided in this application, it should be understood that the disclosed methods and systems can be implemented in other ways. The system embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, and can be electrical, mechanical, or other forms. Furthermore, in the various embodiments of the present invention, all functional units can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0092] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0093] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for monitoring and behavioral intervention in pig farming based on an improved YOLOv11. Its features include the following steps: The system collects video data from inside the pigsty in real time using a camera, and transmits the video data to a processor for preprocessing to extract key video frames. An improved YOLOv11 algorithm was used to construct a pig behavior detection model. The key video frames were imported into the pig behavior detection model for feature extraction. Features at different scales were aggregated and enhanced to generate feature maps. Finally, the detection head was used to achieve accurate recognition of pig behavior. Based on the micro-behavioral characteristics of pigs, it is determined whether fighting will occur in the short term. If it is determined that fighting will occur, a fighting warning is triggered. When fighting is detected, an intervention mode is triggered, and intervention and adjustment methods are selected from the management decision database based on the pigs' behavioral status and environmental status. The detection and identification results and intervention and adjustment records are stored in the database and fed back to the pig behavior detection model and management decision database for model and strategy updates. Based on the micro-behavioral characteristics of pigs, it is determined whether fighting will occur in the short term. If it is determined that fighting will occur, a fighting warning is triggered. Specifically: The micro-behavioral features of pigs in each frame are detected in real time using a pig behavior detection model. These micro-behavioral features include posture features, motion features, and interaction features. A sliding time window is constructed to extract the continuous behavioral sequence of pigs within the window. A spatiotemporal feature encoder is constructed using 1D convolution and BiLSTM networks, and the contribution weights of each feature are calculated through a self-attention mechanism to obtain the encoded feature vector. The feature vector is compared with the pre-defined pre-fighting behavior features in the pre-defined pre-fighting behavior library to obtain the matching weight. Based on the initial pattern weight set according to the pig behavior category in the continuous behavior sequence, the dynamic fighting risk is quantified using the matching weight and the initial pattern weight. If the cumulative fighting risk in the window is greater than the preset threshold, it is determined that a fight between pigs is about to occur. Based on the accumulated struggle risk, a pre-set graded early warning mechanism is used to trigger graded struggle warnings in real time.
2. The pig farming monitoring and behavioral intervention method based on improved YOLOv11 according to claim 1, characterized in that, Video data from inside the pigsty is collected in real time via a camera, and the video data is transmitted to a processor for preprocessing to extract key video frames. Specifically: High-definition cameras deployed in the pigsty continuously capture real-time video streams of the pigsty at a fixed frame rate. The real-time video streams are then transmitted to the processor via a wireless network. After receiving the video streams, the processor performs noise reduction, illumination correction, and background separation to obtain pre-processed video streams. The motion vectors of pigs in the video stream are obtained by optical flow calculation. The motion direction and speed are extracted as local features. Key motion regions in the video stream are obtained by spatiotemporal interest point detection. The dynamic changes of the pig's head and limbs are captured. Local motion features are generated based on the local features and the dynamic changes of the pig's head and limbs. The local motion features are encoded, and the continuous motion data is discretized into semantic units. The encoded local motion features are mapped to a high-dimensional semantic space through an autoencoder network. The K-means clustering algorithm is used to cluster the feature vectors with semantic labels to generate an action semantic dictionary. The similarity between the local motion features of the video stream and the cluster centers in the action semantic dictionary is calculated. Video frames with similarity higher than the threshold are selected as candidate key frames. Redundant frames are removed by combining temporal continuity analysis, and key video frames are extracted.
3. The pig farming monitoring and behavioral intervention method based on improved YOLOv11 according to claim 1, characterized in that, A pig behavior detection model is constructed using an improved YOLOv11 algorithm, specifically as follows: The improved YOLOv11 algorithm is based on the CSPDarknet architecture, which combines fast spatial pyramid pooling and cross-stage local spatial attention as the backbone network. A multi-scale feature fusion module is used to construct the neck structure of the YOLOv11 algorithm. The improved YOLOv11 algorithm is constructed based on the backbone network, neck structure, detection head and optimized loss. A pig behavior detection model was built based on the improved YOLOv11. The complex structure in the original C3k2 module was replaced with FasterBlock of FasterNet. In FasterBlock, partial convolution and two layers of standard convolution were used, and residual connections were made with the input to perform lightweight feature extraction. Channel and spatial attention modules are embedded at the junction of the backbone network and the neck structure. Channel attention is used to adjust the feature channel weights, and spatial attention is used to enhance the target location information, so that the model focuses on the key areas of the pig. FocalEIOULoss is adopted as the regression loss function for bounding boxes. The absolute difference terms of width and height are introduced. Combined with the FocalLoss mechanism, higher loss weights are applied to occluded samples and small target samples, guiding the model to pay more attention to these difficult-to-detect targets. Collect monitoring videos of pigsties, label the pig locations and behavior categories to construct a pig behavior dataset, pre-train the backbone network of the pig behavior detection model on a general object detection dataset, initialize the model parameters, fine-tune using the pig behavior dataset, and optimize the position regression and behavior classification of the detection heads.
4. The pig farming monitoring and behavioral intervention method based on improved YOLOv11 according to claim 1, characterized in that, The key video frames are imported into a pig behavior detection model for feature extraction. Features at different scales are aggregated and enhanced to generate a feature map. The feature map is then used to identify pig behavior. Specifically: Key video frames containing significant behavioral information are obtained and imported into a pig behavior detection model. Shallow features and deep semantic features are extracted in the backbone network through convolutional layers and C3k2-faster modules, and multi-scale feature maps are output. By fusing feature maps of different scales through a fast spatial pyramid pooling module, and further aggregating features through a cross-stage local spatial attention module, and then using a bidirectional feature pyramid network to achieve top-down and bottom-up feature fusion after channel and spatial attention weighting, an optimized feature map is obtained. The detection head generates bounding box coordinates and behavior category probabilities based on the optimized feature map, matches the predicted bounding boxes with the action semantic dictionary, and determines the pig behavior category by combining the temporal context.
5. The pig farming monitoring and behavioral intervention method based on improved YOLOv11 according to claim 1, characterized in that, When fighting behavior is detected among pigs, an intervention mode is triggered. Based on the pigs' behavioral state and the environmental state, intervention and adjustment methods are selected from the management decision database. Specifically: When fighting behavior among pigs is detected, the conflict area is magnified by a high frame rate camera for visual verification to confirm whether actual physical contact has occurred. Temporal verification is used to check whether the fighting behavior continues for more than a threshold time, and group verification is used to analyze whether a chain reaction occurs among the surrounding pigs. Based on the review results, the pig conflict level is classified, and the pig behavior status is generated by combining the pig behavior characteristics. At the same time, the current environmental parameters are obtained to generate the environmental status. Obtain historical intervention examples that include voice and physical adjustments; analyze the intervention type, applicable scenarios, and priority based on each historical intervention example; store the results in a pre-built management decision library; and label each intervention example with matching features. A behavior-intervention bipartite graph is constructed based on the current pig behavior status and intervention measures in the management decision database. Edge weights are constructed in the behavior-intervention bipartite graph based on the historical intervention success rate. The pigs are located in the behavior-intervention bipartite graph based on their current behavior status. Starting from the location node, a random walk is performed. The probability of reaching each intervention node is calculated based on the edge weight. The walk ends when a physical intervention node is reached, and a walk path is generated. The intervention node with the highest visit frequency in the walk path is counted. If there are nodes with the same frequency, the intervention node with higher priority is selected, and the intervention adjustment method is output.
6. The pig farming monitoring and behavioral intervention method based on improved YOLOv11 according to claim 1, characterized in that, The detection and identification results and intervention records are stored in the database and fed back to the pig behavior detection model and management decision database for model and strategy updates. Specifically: The detection and identification results and intervention and adjustment records are structured to generate a detection result table and an intervention record table. The detection result table and intervention record table are periodically batch processed to merge multiple intervention records of the same event and to statistically analyze the behavioral frequency heat map of each pig house area. Data augmentation was performed on the newly added pig fighting behavior samples, the backbone network of the pig behavior detection model was frozen, the classification weights of the detection heads were fine-tuned, incremental updates of the model were achieved, the weights of the pig prodromal behavior categories were recalculated based on the intervention effect rating, the time window was adjusted to be larger, and the short-term prediction accuracy was optimized. Based on the evaluation of intervention effects, intervention records that meet the preset requirements are selected, and the corresponding combinations of pig behavioral characteristics are extracted to establish an efficient intervention model knowledge graph. Intervention measures with more than a preset threshold of consecutive failures are downgraded in priority.
7. A pig farming monitoring and behavior intervention system based on an improved YOLOv11, characterized in that, The system is used to implement the pig farming monitoring and behavior intervention method based on the improved YOLOv11 as described in any one of claims 1-6. The system includes: a data acquisition module, a data preprocessing module, a pig behavior detection module, a fight early warning module, a behavior intervention module, and a data management module. The data acquisition module collects video data from inside the pigsty in real time through a camera and transmits it to the processor via a wireless network. The data preprocessing module transmits video data to the processor for preprocessing and extracts key video frames. The pig behavior detection module uses an improved YOLOv11 algorithm to build a pig behavior detection model. The key video frames are imported into the pig behavior detection model for feature extraction. Features at different scales are aggregated and enhanced to generate a feature map, which is then used to identify pig behavior. The fighting warning module determines whether pig fighting will occur in the short term based on the pigs' micro-behavioral characteristics. If it determines that fighting will occur, it triggers a fighting warning. When the behavior intervention module detects fighting behavior among pigs, it triggers an intervention mode and selects intervention and adjustment methods from the management decision database based on the pigs' behavior and environmental conditions. The data management module stores the detection and identification results and intervention and adjustment records in the database, and feeds them back to the pig behavior detection model and management decision database for model and strategy updates.