Method and device for preventing sow from pressing piglets to death
By monitoring the position and posture of sows and piglets in real time, and using image segmentation and low-frequency electrical pulse stimulation to intervene in the sow's posture, combined with an alarm system, the problem of sows crushing piglets has been solved, improving the safety of the farrowing process and the survival rate of piglets.
Patent Information
- Application Number
- CN202510921681.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-04
- Publication Date
- 2025-11-14
AI Technical Summary
The phenomenon of sows crushing piglets to death during farrowing occurs frequently, and existing measures are insufficient to prevent it in a timely and effective manner, resulting in piglet injuries and economic losses.
By monitoring the position and posture of sows and piglets in real time, using image segmentation and low-frequency electrical pulse stimulation to intervene in the sow's posture, and combining with an alarm system, real-time monitoring and prevention of sow crushing accidents can be achieved.
It improves the safety of sows during farrowing and the survival rate of piglets, reduces the occurrence of piglet crushing accidents, and ensures the survival rate of piglets.
Smart Images

Figure CN120953906A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of animal husbandry technology, and in particular to a method and apparatus for preventing sows from crushing piglets. Background Technology
[0002] In pig production, accidents such as sows crushing piglets while lying down (commonly known as "piglet crushing") occur frequently during the farrowing stage. These accidents not only cause injury or death to piglets, resulting in economic losses for farmers, but also affect the safety management of pig production. To reduce the occurrence of piglet crushing accidents, a common measure is to install gestation crates in the farrowing pen to restrict the sow's movement and provide piglets with hiding space. However, even with gestation crates, piglets may still be injured or killed when the sow turns over or lies down because she cannot escape in time.
[0003] Currently, preventing sows from crushing piglets mainly relies on manual supervision by farm workers. This involves promptly moving the piglets away or gently patting the sow to slow her descent before she lies down. This manual method is labor-intensive and difficult to cover all farrowing pens in a timely manner; accidents can still occur if supervision is neglected. Furthermore, existing solutions are often implemented after piglet crushing has occurred, making it difficult to undo the damage. In addition, some methods attempt to use auditory stimuli (such as alarms) to alert the sow to stand up, but excessively loud noises may startle the piglets, having the opposite effect. Summary of the Invention
[0004] This invention provides a method and apparatus for preventing sows from crushing piglets, overcoming the shortcomings of existing technologies where measures to prevent sows from crushing piglets are not timely and effective enough, and realizing real-time monitoring and proactive prevention of sow crushing accidents, thereby improving the survival rate of piglets.
[0005] This invention provides a method for preventing sows from crushing piglets, comprising: Acquire first real-time images of the sow and piglets, perform position detection on the piglets based on the first real-time images, and perform first pose detection on the sow based on the first real-time images; When the result of the first posture detection indicates that the sow is about to lie down in the area below her body, and the position detection result is in the area below her body, an intervention is triggered on the sow's posture, and the piglets are marked as being in a dangerous state. Based on the second real-time images of the sow and piglets marked as dangerous, a second pose detection is performed on the sow; when the result of the second pose detection indicates that the sow still wants to lie down in the area under her body, the second real-time image is segmented to obtain the body coverage area of the sow and the target area of the piglets marked as dangerous. An alarm is triggered when the body coverage area covers the target area and the target area does not move within a preset time period.
[0006] In some embodiments, the step of detecting the piglet's location based on the first real-time image includes: The YOLOv11 model is invoked to perform first target detection on each frame of the target image in the first real-time image, thereby obtaining the first target position of each piglet in the target image; For each piglet, a target tracking algorithm is invoked to predict the movement trend of the first target position, thereby obtaining the piglet's movement trajectory.
[0007] In some embodiments, the step of detecting the first pose of the sow based on the first real-time image includes: Based on each frame of the target image in the first real-time image, skeletal key points of the sow are detected to obtain multiple skeletal key points of the sow at the elbow joint of the forelimb. Based on the skeletal key points, construct the limb segment vector of the sow's forelimb elbow joint in the target image, and calculate the angle between the limb segment vectors; When the included angle is less than the angle threshold, it is determined that the sow is in a position where she is about to lie down in the area below her body; or, For each frame of the target image in the first real-time image, determine the height of the highest point of the sow's back or the lowest point of her abdomen from the ground; For two target images with adjacent frame numbers in the first real-time image, calculate the rate of change of the height value; When the rate of change is greater than the rate threshold, it is determined that the sow is in a position where she will lie down in the area under her body.
[0008] In some embodiments, triggering intervention in the sow's posture includes: A first intervention command is sent to an intervention device located on the sow's leg. The first intervention command is used to trigger the intervention device to generate a first low-frequency electrical pulse signal to perform a first stimulation on the sow's leg. One second after the first stimulus is delivered, the sow's third posture is detected using the first real-time image; When the result of the third posture detection indicates that the sow still wants to lie down in the area under her body, a second intervention command is sent to the intervention device. The second intervention command is used to trigger the intervention device to generate a second low-frequency electrical pulse signal to perform a second stimulus on the sow's legs. The amplitude of the second low-frequency electrical pulse signal is greater than the amplitude of the first low-frequency electrical pulse signal.
[0009] In some embodiments, the location detection of piglets based on the first real-time image is implemented by calling an object detection model, and the first pose detection of sows based on the first real-time image is implemented by calling a pose estimation model. The training process of the object detection model includes: Obtain an image dataset of sows and piglets during their activities, wherein each training image in the image dataset is marked with the true location of the sow's skeletal key points and the true bounding box of the piglet; The image dataset is input into the object detection model for forward propagation to obtain the predicted bounding box of the piglets; A multi-task loss function is constructed based on the ground truth bounding box and the predicted bounding box, and then backpropagated through the multi-task loss function in the object detection model to update the parameters of the object detection model.
[0010] The training process of the pose estimation model includes: The image dataset is input into the pose estimation model for forward propagation to obtain the predicted locations of the skeletal key points of the sow; A mean squared error loss function is constructed based on the predicted position and the actual position, and then backpropagated through the mean squared error loss function in the attitude estimation model to update the parameters of the attitude estimation model.
[0011] In some embodiments, the method further includes: In the second real-time image, two target images whose shooting time interval exceeds a preset time period are identified; If the target region is in the same position or size in the two target images, then it is determined that the target region has not moved within the preset time period.
[0012] The present invention also provides a device for preventing sows from crushing piglets, characterized in that it includes: a monitoring camera, an edge device, a stimulation device, and an alarm, wherein the edge device includes a detection module, a triggering module, and a processing module; The detection module is used to acquire a first real-time image of the sow and piglets through the monitoring camera, perform position detection on the piglets based on the first real-time image, and perform a first posture detection on the sow based on the first real-time image. The triggering module is used to trigger the stimulation device to intervene in the sow's posture and mark the piglets as dangerous when the result of the first posture detection indicates that the sow is about to lie down in the area below her body and the result of the position detection is in the area below her body. The processing module is used to perform a second posture detection on the sow after intervention based on the second real-time images of the sow and the piglets marked as dangerous. When the result of the second posture detection indicates that the sow after intervention still lies down in the area below her body, the second real-time image is segmented to obtain the body coverage area of the sow and the target area of the piglets marked as dangerous. The triggering module is also used to trigger the alarm when the body coverage area covers the target area and the target area does not move within a preset time period.
[0013] Furthermore, the stimulation device includes: a lithium battery, a discharge drive board, a safety protection device, and a communication device; The lithium battery is used to power the discharge drive board, the safety protection device, and the communication device. The communication device is used to communicate with the edge device via the network, and when it receives an intervention command sent by the edge device, it triggers the discharge drive board to output a low-frequency electrical pulse signal. The safety protection device is used to cut off the power supply from the lithium battery to the discharge drive board when the current, temperature, or output time of the low-frequency electrical pulse signal output by the discharge drive board reaches a corresponding threshold.
[0014] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method for preventing sows from crushing piglets as described above.
[0015] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for preventing sows from crushing piglets as described above.
[0016] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the method for preventing sows from crushing piglets as described above.
[0017] The method for preventing sows from crushing piglets provided by this invention monitors the position and posture of the sow and piglets in real time, uses image segmentation to promptly detect the risk of crushing, and automatically intervenes in the sow's posture to delay her lying down, thus buying time for the piglets to escape and preventing crushing accidents. Furthermore, an alarm is triggered when automatic intervention fails, further improving the reliability of preventing sows from crushing piglets. Thus, through this dual mechanism of automatic intervention and alarm, the safety of the sow's farrowing process and the survival rate of piglets are significantly improved. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced one by one below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0019] Figure 1 This is a flowchart illustrating the method for preventing sows from crushing piglets, provided by the present invention.
[0020] Figure 2 This is a structural example diagram of the edge device provided by the present invention.
[0021] Figure 3 This is an application example diagram of the device provided by the present invention to prevent sows from crushing piglets.
[0022] Figure 4 This is a schematic diagram of the stimulation device provided by the present invention.
[0023] Figure 5 This is a schematic diagram of the structure of an electronic device provided by the present invention.
[0024] Figure label: 1: Sow; 2: Piglets; 3: Protective fence; 4: Monitoring camera; 5: Edge device; 6: Stimulation device; 7: Alarm; 8: Lithium battery; 9: Discharge drive board; 10: Safety protection device; 11: Communication equipment; 12: 4G communication module. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0026] The method and apparatus for preventing sows from crushing piglets according to the present invention will be described below with reference to the accompanying drawings. Figure 1 This is a flowchart illustrating the method for preventing sows from crushing piglets provided by the present invention, as shown below. Figure 1 As shown, the method includes steps 101 to 104, which are described in detail below.
[0027] Step 101: Obtain the first real-time images of the sow and piglets, perform position detection on the piglets based on the first real-time images, and perform first pose detection on the sow based on the first real-time images.
[0028] See also Figure 3 The process begins by acquiring first real-time images of sow 1 and piglet 2 using monitoring equipment, specifically image data of the lower abdominal area of sow 1. Both sow 1 and piglet 2 are located within the farrowing pen 3. Monitoring devices with different viewing angles can be installed on the side rails of the farrowing pen 3 to capture real-time images, thereby reducing blind spots. The monitoring equipment can be a camera 4, with shooting intervals set according to fixed time periods. The first real-time image acquired is an image sequence composed of a set of target images. Of course, multiple sets of target images from different perspectives can be captured using monitoring devices with different viewing angles.
[0029] Next, individual segmentation and keyframe extraction are performed on the first real-time images to monitor the piglet positions and sow postures. For piglets, position detection is performed based on the first real-time images to identify their position and movement trajectory within the stall. For sows, first posture detection is performed based on the first real-time images to determine whether the sow should lie down in the area under her body, thereby determining whether "trampling" of piglets has occurred.
[0030] In some embodiments, the location detection of piglets based on the first real-time image can be achieved in the following ways, which are described in detail below.
[0031] First, the YOLOv11 model is called to perform first target detection on each frame of the first real-time image to obtain the first target position of each piglet in the target image.
[0032] Here, target detection is performed in each frame of the target image to identify all piglets within the restraint bar, thereby obtaining the location information of each piglet. Specifically, a deep learning target detection model is used to accurately locate the piglets and mark them with bounding boxes.
[0033] Optionally, the target detection model in this embodiment of the invention uses the YOLOv11 model. The YOLO model has end-to-end detection capability and high-speed real-time performance, and can simultaneously detect multiple piglet targets in a single frame of target image.
[0034] The YOLOv11 model employs an improved backbone network and detection head to enhance feature extraction efficiency and multi-scale object detection capabilities. A cross-stage partial fusion structure and a novel attention mechanism are introduced into the network backbone to enhance feature representation while maintaining computational efficiency. The YOLO detection head uses a Feature Pyramid Network (FPN) to fuse feature maps of different scales, enabling simultaneous detection of large-sized sows and small-sized piglets, making it more robust to detecting targets of varying sizes. In this embodiment, the trained YOLO model can accurately identify the location of each piglet in an image and return the corresponding bounding box coordinates and confidence score.
[0035] Furthermore, to improve the recognition accuracy of the object detection model, this embodiment introduces a Transformer self-attention mechanism into the YOLO model to enhance global feature capture. Specifically, it is assumed that the YOLO backbone network outputs a feature map during the feature extraction stage. The size is ,in and For the height and width of the feature map, The number of channels. The feature map is transformed using a linear transformation. Projection yields the query matrix Key matrix Sum matrix As shown in formula (1): (1) In the above formula (1), , , Representing the query matrix Key matrix Value matrix The corresponding weight matrix.
[0036] Next, calculate the query matrix. AND key matrix The correlation is used to obtain the attention weight matrix. And using attention weight matrix Log-value matrix A weighted summation is performed to obtain an enhanced feature map that incorporates global contextual information. The formula is as follows: (2) (3) The enhanced feature map described above Re-feeding the YOLO detection head effectively combines local features extracted by convolution with global features extracted by self-attention, thereby improving the detection accuracy of piglets. The improved YOLO detection model can maintain real-time performance while improving the detection accuracy of piglets and its adaptability to complex scenes.
[0037] In some embodiments, joint detection can be performed by combining first real-time images captured by monitoring devices from different perspectives. The features of a single frame target image extracted from each set of first real-time images can be denoted as... Let n be the number of groups of the first real-time image. Then, the learned parameter matrix is used to perform a weighted summation of each feature, or the contribution of each feature is adaptively determined through a gating unit. Finally, a gating function is used. For any two of these features and To merge: (4) (5) In formulas (4) and (5) above, Indicates features and characteristics splicing, For a learnable parameter matrix, This is the Sigmoid activation function. This represents the final fused features, which are then input into the YOLOv11 model for prediction.
[0038] Through the above methods, the system can automatically balance the uncertainty of information from different sources, achieve effective fusion of multiple features, and improve the accuracy and robustness of risk assessment for betting on offspring.
[0039] For each frame of the target image, the YOLOv11 model outputs the corresponding bounding box coordinates and confidence score of the piglet. These bounding box coordinates represent the piglet's first target location.
[0040] Next, for each piglet, a target tracking algorithm is called to predict the movement trend of the first target position, thus obtaining the piglet's movement trajectory. Since the target images are continuous frames, the first target position of each piglet changes in these target images. Therefore, for multiple frames of target images, target tracking is performed on the detected first target positions of each piglet to obtain the movement trajectory of each piglet over time.
[0041] Target tracking can be achieved using target tracking algorithms, such as multi-target tracking algorithms and Kalman filtering. Each piglet is assigned an identification tag, and its position is updated in real time. Even if individual piglets in a frame of the target image experience brief occlusion or detection interruption, their current position can be predicted based on previous trajectories. From a side-view monitoring angle, the occlusion of the piglets by the sow's body is somewhat mitigated; however, if a piglet briefly disappears from the camera's view, its last position and direction of movement before disappearing can be combined to determine if it has entered the danger zone beneath the sow's body. For piglets briefly obscured by the sow's torso, the piglet's trajectory can be maintained within a preset time window, and identification and matching can continue when it reappears from the occlusion, thus achieving trajectory compensation under occlusion conditions and avoiding missed detection of dangerous situations due to momentary occlusion.
[0042] In the implementation process, a Kalman filter prediction model can be used to make short-term predictions of the piglet's movement trajectory to improve the accuracy of position inference under occlusion conditions. The Kalman filter predicts the state at the current time t based on the state at the previous time t-1, and corrects it by incorporating new observations. Its state update and prediction process can be described as follows: First, determine the predicted state of the prediction model. As shown below: (6) In the above formula (6), This is the observation value of the first target location of the piglet detected in the target image of the current frame. Then, based on the observation value of the detected piglet location in the target image of the current frame... To update the state estimate, as shown below: (7) In the above formula (7), Here is the state transition matrix. For the observation matrix, This represents the Kalman gain at the current moment. Through the above prediction-correction process, the system can estimate the location of a piglet when it is temporarily lost, and correct its trajectory when it reappears, thus achieving accurate detection of the piglet's movement trajectory.
[0043] Furthermore, deep learning-based sequence modeling methods can be introduced here to predict piglet trajectories over longer time scales. For example, by using a Long Short-Term Memory (LSTM) network to encode time-series information, patterns in piglet movement trajectories can be learned, thereby predicting piglet movement trends in advance. This model uses... Sequence of the first target location of the piglet in the frame target image As input, update the inner hidden layer state and output the position prediction for the next time step. By training the sequence model to minimize the error between the predicted sequence and the actual movement sequence, the sequence model can predict the possible escape direction and speed of piglets to a certain extent, providing a more sufficient basis for risk assessment. In this embodiment of the invention, the YOLOv11 model and target tracking algorithm are used to detect the position and predict the movement trajectory of piglets, thereby more accurately determining whether piglets are in danger of being crushed by the sow. Even when piglets are briefly blocked by the sow's torso, trajectory compensation can be achieved through movement trajectory prediction to avoid missing the danger due to momentary occlusion.
[0044] In some embodiments, the first pose detection of the sow based on the first real-time image can be implemented in the following manner, which is described in detail below.
[0045] To determine if piglets are at risk of being crushed by the sow's sitting posture, it's necessary to monitor the sow's position in real time. Lying down refers to sitting or lying down in the area beneath the sow's body. This area can be defined as the danger zone, which represents the area projected onto the ground by the sow's abdomen when she is standing, plus a certain surrounding radius. If the piglet's primary target position is in this area, it's certain that the piglet may be at risk of being crushed by the sow's sitting posture. The process of detecting the sow's posture is described below.
[0046] First, based on each frame of the target image in the first real-time image, skeletal key points of the sow are detected to obtain multiple skeletal key points of the sow's elbow joint in the forelimb.
[0047] Specifically, for each frame of the target image in the first real-time image, skeletal keypoint detection can be performed to extract the spatial positions of the sow's major joints and trunk, thereby obtaining posture parameters. In a gestation stall environment, common sow postures include standing, sitting, and lying down. As the sow gradually transitions from standing to sitting or lying down, its postural characteristics undergo continuous changes, such as bending its forelimbs to kneel, folding its hind limb joints, lowering its center of gravity, and decreasing its abdominal height. Thus, by analyzing the changes in the positions of the sow's skeletal keypoints in consecutive frames of the target image, the dynamic features of the sow's posture changes can be extracted.
[0048] Then, based on the skeletal key points, the limb segment vector of the sow's forelimb elbow joint in the target image is constructed, and the included angle of the limb segment vector is calculated.
[0049] Limb segment vectors can be constructed from multiple skeletal keypoints. The forelimb elbow has multiple limb segments (i.e., joints). Two skeletal keypoints correspond to one limb segment, three skeletal keypoints correspond to two limb segments, and two limb segments can be used to construct two limb segment vectors. Here, for each frame of the target image in the first real-time image, the angle between the limb segment vectors is calculated, denoted as . The angle between the limb segment vectors is used to measure the degree of flexion of the elbow joint of the forelimb over a certain period of time. The calculation formula is as follows: (8) (9) In the above formula (8), and These represent the vectors of two limb segments at the elbow joint of the sow's forelimb.
[0050] When the included angle is less than the angle threshold, it is determined that the sow is in a posture about to lie down in the area under her body. When the bending angle of the sow's forelimb elbow joint is less than the preset angle threshold in a certain frame of the target image, it indicates that the sow's forelimbs are kneeling, and it can be further determined that the sow has a tendency to quickly press down (lie down), that is, to lie down in the area under her body.
[0051] Of course, embodiments of the present invention can also determine posture by calculating the spread angle of the sow's hind leg joints and setting an angle threshold accordingly. When the spread angle reaches the angle threshold, it also indicates that the sow's hind legs are folding in preparation for lying down. Through comprehensive analysis of the posture angles and positions of multiple key points, a trend signal is generated indicating that the sow will lie down in the area under her body, which is used to indicate that the current posture change of the sow has reached a level that may crush the piglets.
[0052] In some embodiments, the sow is subjected to a first posture detection based on the first real-time image, and the sow is also judged to be in a lying position by judging the height changes of the sow's back and abdomen.
[0053] Specifically, for each frame of the target image in the first real-time image, the height of the highest point of the sow's back or the lowest point of its abdomen above the ground is determined. As the sow gradually changes from standing to sitting or lying down, the height of her back or abdomen above the ground will continuously decrease. Therefore, the height of the highest point of the sow's back or the lowest point of its abdomen above the ground in each frame of the target image can be monitored to determine the rate of change of the height value.
[0054] Next, for two adjacent target images in the first real-time image, the rate of change of height value is calculated. Here, there is a shooting time interval between two adjacent target images. First, the difference in height value between the two target images is calculated, and then the ratio of the difference to the shooting time interval is used as the rate of change of height value.
[0055] Finally, it is determined whether the rate of change of the height value exceeds a preset rate threshold. When the rate of change exceeds the rate threshold, it is determined that the sow is in a position where she is about to lie down in the area under her body. When the height value of the back or abdomen is detected to be continuously decreasing and the rate of decrease exceeds the preset threshold, it indicates that the sow is showing a tendency to quickly press down (lie down), exhibiting a lying-down posture in the area under her body.
[0056] In practice, for the first real-time image, the sow's lying posture can be determined by calculating the angle between the elbow joint of the sow's forelimb and the limb segment vector in the target image, or by calculating the rate of change of the height of the highest point of the sow's back or the lowest point of her abdomen from the ground. Either method is sufficient. Of course, both methods can be used simultaneously for more accurate judgment.
[0057] In this embodiment of the invention, the posture of the sow is detected by using a first real-time image. The detection is performed simultaneously by using the angle between the elbow joint of the sow's forelimb in the target image and the rate of change of the height of the highest point of the sow's back or the lowest point of the abdomen from the ground. This ensures the accuracy of posture detection and enables effective detection of the sow lying down in the area below its body.
[0058] Step 102: When the result of the first posture detection indicates that the sow is about to lie down in the area below her body, and the result of the position detection is in the area below her body, the sow's posture is intervened and the piglets are marked as dangerous.
[0059] After performing the first posture detection on the sow and the first position detection on the piglets using the first real-time image in step 101 above, it is necessary to determine whether any piglets are in a dangerous state. Here, when the result of the first posture detection indicates that the sow is about to lie down in the area below her body, and the result of the position detection is also in the area below her body, intervention is triggered on the sow's posture, and the piglets are marked as being in a dangerous state.
[0060] Here, the location detection result is determined to be within the area below the mother's body. This can be determined by judging whether the piglet's movement trajectory passes through the area below the mother's body. If the movement trajectory passes through, it means that the piglet will pass through the area below the mother's body when it moves. Otherwise, it means that the piglet will not move to the area below the mother's body.
[0061] Since monitoring devices at the same viewing angle can capture multiple sets of target images from different perspectives, i.e., multiple first real-time images, each first real-time image can perform first posture detection for the sow and first position detection for the piglets. Therefore, this embodiment of the invention designs a decision mechanism that integrates the detection results of multiple monitoring devices. For example, it combines "the sow is about to lie down in the area below her body" and "the piglet's position detection result is in the area below her body" into a bimodal decision input. When both conditions are true, intervention is triggered; if either condition is not met, it is considered a risk-free situation. This decision logic can be formalized as a fusion decision function. This allows for the combination of outputs from different modalities for the final risk assessment. For example, suppose... A Boolean variable indicating that the piglet's location detection result is located in the region below its body. A Boolean variable representing the area under the sow's body where she will lie down indicates the triggering condition for a risk event. It can be represented as: (10) When the fusion determination function When a risk event is triggered, it indicates that the sow may be sitting on and crushing the piglets if she lies down in the area beneath her body. Therefore, intervention to control the sow's posture is required, and the piglets should be marked as being in a dangerous state. Of course, there may be more than one piglet; as long as even one piglet is at risk of being crushed by the sow, intervention to control the sow's posture must be triggered. This intervention is generally done in a non-audible manner to avoid disturbing the piglets with loud noises.
[0062] The following describes the process of triggering interventions in the sow's posture.
[0063] First, a first intervention command is sent to the intervention device positioned on the sow's leg. This command triggers the device to generate a first low-frequency electrical pulse signal, which stimulates the sow's leg. By sending a command to the device, the device outputs a low-frequency electrical pulse signal, applying electrical pulse stimulation to the sow's leg. This stimulates the sow's leg through tactile stimulation, alerting her to the piglets' location and causing her to slow down or change her lying position. The intensity of this electrical pulse stimulation is carefully controlled to attract the sow's attention, avoiding excessive fear or startling the piglets. Under this intervention, the sow's lying down speed is significantly slowed. Ideally, the stimulation may cause the sow to stop lying down and stand up again, or at least lie down slowly for a longer period, giving the piglets sufficient time to escape from directly beneath the sow's body.
[0064] However, the initial intervention may not be stimulating enough for the sow. Therefore, to verify whether the sow's posture has changed, this embodiment of the invention performs a third posture detection on the sow using a first real-time image one second after the first stimulus is applied.
[0065] Here, after intervening and stimulating the sow, the first real-time image of the sow and piglets is still obtained through monitoring equipment, and the sow's third posture is detected. The posture detection method can refer to step 101 above, which will not be repeated here.
[0066] When the third posture detection indicates that the sow still intends to lie down in the lower part of her body, a second intervention command is sent to the intervention device. This second intervention command triggers the intervention device to generate a second low-frequency electrical pulse signal to apply a second stimulus to the sow's legs. The amplitude of the second low-frequency electrical pulse signal is greater than the amplitude of the first low-frequency electrical pulse signal.
[0067] Here, when the third posture detection indicates that the sow is still about to lie down in the area beneath her body, it means that the first stimulation from the intervention device was ineffective and did not interfere with the sow's intended lying posture. At this point, a second intervention command is sent to the intervention device to perform a second electrical pulse stimulation on the sow. The amplitude of the low-frequency electrical pulse signal used in the second stimulation is greater than that of the first, ensuring that the sow senses the abnormal stimulation, becomes alert, and temporarily stops pressing down on her body, allowing the piglets in the area beneath the sow's body to escape and avoid the dangerous situation.
[0068] When the third posture detection result indicates that the sow will not lie down in the area under her body, it means that the electrical pulse stimulation of the intervention device has interfered with the sow's movement and thus changed her lying posture. At this time, there is no risk of the piglets being crushed. At this time, the intervention is stopped and the sow and piglets are monitored.
[0069] In this embodiment of the invention, when it is determined that the sow is about to lie down in the area under her body, and the piglet's position is detected as being in the area under her body, an intervention device installed on the sow automatically applies multiple electrical pulses with gradually increasing amplitude to the sow, prompting her to change her lying-down posture. This ensures that the piglets in the area under the sow's body can escape, thereby improving the piglet's survival rate.
[0070] Step 103: Based on the second real-time images of the sow and piglets, perform second pose detection on the sow after intervention. When the result of the second pose detection indicates that the sow still needs to lie down in the area under her body, segment the second real-time image to obtain the body coverage area of the sow.
[0071] After intervening in the sow's posture in step 103, the sow and piglets inside the pen are monitored by the monitoring equipment, and a second real-time image of the sow and piglets is obtained to determine whether the intervention measures on the sow's posture have been effective.
[0072] Here, based on the second real-time images of the sow and piglets, the second pose of the sow after intervention is detected. Of course, the method of second pose detection is still similar to step 101 above, and they can be referred to each other. It will not be repeated here.
[0073] When the second posture detection result indicates that the sow still intends to lie down in the area beneath her body, the second real-time image is segmented to obtain the area covered by the sow's body. If the second posture detection result shows that the sow still intends to lie down in the area beneath her body, it means that the two electrical pulse stimuli from the intervention device had no effect on the sow; the sow did not respond sufficiently to the electrical pulse stimuli from the intervention device and still quickly lay down. Simultaneously, the piglets did not escape, thus it can be determined that the event of the sow crushing the piglets may have occurred.
[0074] Therefore, the next step is to analyze the relative positional relationship between the sow and the piglets marked as being in danger from the target images in subsequent frames of the second real-time image, in order to determine whether a sow crushing piglet event has occurred.
[0075] Specifically, the second real-time image can be segmented to obtain the area covered by the sow's body and the target area marked as dangerous piglets. Here, for each frame of the target image in the second real-time image, corresponding image segmentation processing is performed to divide the area covered by the sow's body and the target area marked as dangerous piglets. This allows for determining whether the sow has crushed the piglets based on whether the body area covers the target area. This image segmentation processing can be implemented using image segmentation algorithms or object detection algorithms.
[0076] Step 104: When the body coverage area covers the target area and the target area does not move within a preset time period, an alarm is triggered.
[0077] Here, it is necessary to further determine whether the area covered by the sow's body covers the target area of the piglet marked as being in danger. If the area covered by the sow's body partially overlaps with the target area in the target image, it can be determined that the sow may have sat on the piglet. In addition, it is necessary to rule out the special case where the sow's body completely covers the piglet. Therefore, it is necessary to further determine whether the target area has moved within a preset time period, that is, whether the piglet marked as being in danger has moved within a certain time period. If it has not moved, it is determined that it has been sat on by the sow.
[0078] To determine whether the target area of the piglet has changed within the preset time period, it is necessary to use multiple frames of target images from the second real-time image, which will be explained in detail below.
[0079] First, in the second real-time image, two target images whose shooting time interval exceeds a preset time period are identified. Each target image has a shooting time interval, so the corresponding two target images can be determined based on this preset time period. To improve the accuracy of the judgment, the time period can be reasonably preset based on the shooting time interval of the target images, for example, 5 seconds.
[0080] For these two target images, image segmentation is first performed to determine the target area of the piglets marked as being in danger. Then, the position or size of the target area in the two images is compared. If the position or size of the target area is the same in the two images, it is determined that the target area has not moved within a preset time period. In other words, the piglets marked as being in danger have not moved within 5 seconds.
[0081] In this embodiment of the invention, by judging the position or size changes of the target area in multiple frames of target images, it can be determined that the piglets marked as dangerous have not moved within a preset time period. In this way, combined with the body coverage area of the sow, the occurrence of the sow crushing piglets event can be determined more accurately.
[0082] An alarm is triggered when the sow's body covers the target area and the target area does not move within a preset time period. Here, if the sow's body covers the target area of a piglet marked as being in danger, and the piglet's target area does not move within the preset time period, it can be determined that a sow crushing piglet incident has occurred. In this case, manual intervention is needed to control the sow's posture, and an alarm can be triggered to alert farm staff to intervene.
[0083] The alarm can be triggered by a 105dB buzzer and a bright red LED (flashing at 2Hz), lasting for 10 seconds to alert farm staff to intervene immediately. If the risk is not eliminated within 10 seconds, a pre-recorded Chinese voice prompt ("Please check sow in pen X immediately, suspected of piglet crushing!") will play for 15 seconds. The alarm information is simultaneously uploaded to the cloud via a 4G / LTE module. The backend server pushes a JSON message about the sow crushing piglet event to the farm staff's mobile app, the control room screen, or SMS via MQTT / HTTP API. If the buzzer or LED circuit current is abnormal, the system will trigger a backup 85dB buzzer within 5 seconds and record the fault code to ensure the alarm's effectiveness.
[0084] Through the aforementioned automatic alarm measures, even in extreme cases where physical electrical pulse stimulation fails to infect the sow, piglet crushing incidents can be promptly identified and manually addressed, minimizing losses. The method for preventing sows from crushing piglets provided by this invention monitors the position and posture of the sow and piglets in real time, uses image segmentation to promptly detect the risk of crushing, and automatically intervenes in the sow's posture to delay her lying down, thus buying time for the piglets to escape and preventing crushing accidents. Furthermore, an alarm is triggered when automatic intervention fails, further improving the reliability of preventing sows from crushing piglets. Thus, through this dual mechanism of automatic intervention and alarm, the safety of the sow's farrowing process and the survival rate of piglets are significantly improved.
[0085] In some embodiments, position detection of piglets based on the first real-time image is achieved by calling an object detection model, and first pose detection of the sow based on the first real-time image is achieved by calling a pose estimation model. However, the object detection model and pose estimation model need to be pre-trained before performing position detection and pose detection.
[0086] The training process of the object detection model is described below.
[0087] First, an image dataset of sows and piglets' activities is acquired. Each training image in the dataset is marked with the true location of the sow's skeletal keypoints and the true bounding box of the piglet. For scenarios involving piglet crushing during farrowing, a large amount of image and video data containing sow and piglet activities can be collected. Data collection should cover a variety of conditions, including different breeds of sows, different sizes and numbers of piglets, and different lighting and backgrounds in the farrowing house, to ensure the model has good generalization ability. Cameras can be set up in the farrowing house to monitor the entire farrowing process for a long time, extracting segments showing the sow lying down and the piglets moving as training material.
[0088] The collected raw image data needs to be labeled and preprocessed. First, the sows and piglets in the images can be manually labeled: this includes marking the ground truth bounding boxes of each piglet for use in training the object detection model. Additionally, the ground truth locations of the sow's skeletal key points (ears, shoulders, elbows, hips, knees, and limbs) need to be labeled for use in training the pose recognition model. After labeling, blurry, severely occluded, or inaccurately labeled samples are removed to obtain the image dataset.
[0089] To enhance model robustness, the image dataset can be augmented by performing data augmentation on labeled images, such as random cropping and scaling, and horizontal flipping. These augmentations can simulate variations in camera angle, lighting, and partial occlusion, thus preventing the model from overfitting to a specific distribution of the training data. Furthermore, techniques such as Generative Adversarial Networks (GANs) can be used to synthesize simulated data to supplement data on extreme poses or rare scenes.
[0090] In each training iteration, based on a set batch size, the image dataset is input into the object detection model for forward propagation to obtain the predicted bounding boxes of the piglets. Then, a multi-task loss function is constructed based on the ground truth bounding boxes and the predicted bounding boxes, and this multi-task loss function is used for backpropagation in the object detection model to update its parameters. Here, the object detection model can be a YOLOv11 model, and the multi-task loss function can be the loss function used by the YOLOv11 model. Training stops when the number of training iterations reaches a preset number, or when the multi-task loss function begins to converge.
[0091] Furthermore, the training process of the pose estimation model includes: inputting the image dataset into the pose estimation model for forward propagation to obtain the predicted positions of the skeletal key points of the sow; then constructing a mean squared error loss function based on the predicted positions and the actual positions; and backpropagating the mean squared error loss function in the pose estimation model to update the parameters of the pose estimation model.
[0092] Here, the pose estimation model can also use an image object detection model. During training, the image dataset is input into the pose estimation model for prediction according to the corresponding batch sample size. Then, backpropagation is performed through the constructed mean squared error loss function, and the loss function is optimized according to the set number of training iterations. When the number of training iterations reaches the preset number, or the mean squared error loss function begins to converge, training is stopped.
[0093] Furthermore, during model training, the image dataset is divided into training, validation, and test sets (e.g., 7:2:1), using the standard YOLO dataset format. During training, the object detection model employs a multi-task loss function to simultaneously optimize classification accuracy and bounding box regression accuracy. The pose estimation model is trained based on the mean squared error loss of keypoint coordinates. The sequence model updates its parameters by calculating the error between the predicted and true sequences using time-series data.
[0094] During training iterations, a validation set is used to monitor model performance to prevent overfitting and adjust hyperparameters. Common metrics for measuring the performance of object detection models include mean average precision (mAP) and detection accuracy, such as the average AP calculated over multiple IoU thresholds. IoU (Intersection over Union) is defined as shown in Equation (11), and is the predicted bounding box. With the true bounding box Measurement of overlap: (11) In the above formula (11), Represents the predicted bounding box With the true bounding box The area of intersection This represents the area of the union of the two. When If the location of the piglet exceeds the threshold of 0.75, it is considered that the location detection is correct. Based on this, the precision and recall rate are calculated, and the average precision (AP) is further calculated.
[0095] Furthermore, this also uses metrics such as the F1 score to comprehensively evaluate the balance between precision and recall in the detection. The F1 score is the harmonic mean of precision P and recall R, as shown in formula (12): (12) The model parameters that achieve the best performance on the validation set will be finally evaluated on the test set to ensure their effectiveness on unseen data.
[0096] To meet the real-time and low-power requirements of the farm environment during model deployment, various optimization techniques can be employed. First, the trained model is exported to a standard intermediate representation format, and model distillation is used for optimization to accelerate its inference speed on the GPU. Simultaneously, considering the limited computing resources of edge devices, the model is pruned and quantized to improve inference efficiency and reduce energy consumption while minimizing loss of accuracy.
[0097] In this embodiment of the invention, by pre-training the target detection model and the posture estimation model, it is possible to accurately detect the position of piglets and the posture of sows, thereby ensuring real-time control of sow crushing piglets events.
[0098] The device for preventing sows from crushing piglets, provided by the present invention, is described below. Figure 3 As shown, the device to prevent sows from crushing piglets specifically includes a monitoring camera 4, an edge device 5, a stimulation device 6, and an alarm 7.
[0099] Camera 4 is a 4-megapixel infrared network high-definition camera that provides overhead coverage of the activity area of the sow and piglets and outputs a real-time image stream (i.e., the first real-time image and the second real-time image).
[0100] The specific structure of edge device 5 can be as follows: Figure 2 As shown, the edge device 5 includes a detection module 201, a triggering module 202, and a processing module 203.
[0101] Specifically, such as Figure 3 As shown, the detection module 201 is used to acquire the first real-time image of the sow 1 and the piglet 2 through the monitoring camera 4, perform position detection on the piglet 2 based on the first real-time image, and perform first posture detection on the sow 1 based on the first real-time image.
[0102] The trigger module 202 is used to trigger the stimulation device 6 to intervene in the posture of the sow 1 and mark the piglet 2 as dangerous when the result of the first posture detection indicates that the sow 1 is about to lie down in the area below the body and the position detection result is in the area below the body.
[0103] The processing module 203 is used to perform a second pose detection on the sow 1 based on the second real-time image of the sow 1 and the piglet 2 marked as dangerous; when the result of the second pose detection indicates that the sow 1 still wants to lie down in the area under its body, the second real-time image is segmented to obtain the body coverage area of the sow 1 and the target area of the piglet 2 marked as dangerous.
[0104] The trigger module 202 is also used to trigger the alarm 7 when the body coverage area covers the target area and the target area does not move within a preset time period.
[0105] like Figure 3 As shown, the device for preventing sows from crushing piglets also includes a 4G communication module 12, which can be a wireless network communication device. The alarm 7 can be installed around or near the limit fence 3. The alarm 7 receives instructions from the edge device 5 through the 4G communication module 12 to trigger an alarm, including voice broadcasting and remote warning, to alert the farm workers when a piglet crushing accident occurs.
[0106] It should be noted that the beneficial effects of the device used to prevent sows from crushing piglets correspond to those of the methods described above. Therefore, the beneficial effects of the device will not be elaborated here.
[0107] Furthermore, such as Figure 4 As shown, the stimulation device 6 includes: a lithium battery 8, a discharge drive board 9, a safety protection device 10, and a communication device 11. The stimulation device 6 can be a constant current limiting low-frequency electrical pulse generator, with an adjustable elastic strap body. It can be installed on the hind legs of the sow as an intervention device, and can be installed on all four legs as needed. When stimulation is required, all four stimulation devices will stimulate simultaneously.
[0108] Specifically, the lithium battery 8 can be a 4V / 2Ah lithium battery that is hot-swappable. The lithium battery 8 is used to power the discharge drive board 9, the safety protection device 10, and the communication device 11.
[0109] The communication device 11 can be a BLE wireless communication unit used to communicate with the edge device 5 via the network, and triggers the discharge drive board 9 to output a low-frequency electrical pulse signal when it receives an intervention command sent by the edge device.
[0110] The discharge drive board 9 is a boost-constant current dual closed-loop drive board, equipped with soft silver-carbon composite electrode sheets, which can output low-frequency electrical pulse signals with a pulse width of 100-500µs, an amplitude of 20-60mA, and a frequency of 80-150Hz.
[0111] The safety protection device 10 is used to cut off the power supply from the lithium battery 8 to the discharge drive board 9 when the current, temperature, or output time of the low-frequency electrical pulse signal output by the discharge drive board 9 reaches a corresponding threshold. For example, if the temperature of the discharge drive board 9 is greater than 55 degrees or the output time reaches 8 seconds, the power supply from the lithium battery 8 will be cut off.
[0112] In this embodiment of the invention, the stimulation device can accurately apply electrical pulse stimulation to the legs of the sow during intervention. By controlling and using low-frequency electrical pulse signals through safety protection equipment, a silent intervention is achieved, which can avoid startling the sow and piglets and causing additional accidents while applying electrical pulse stimulation.
[0113] It should be noted that the beneficial effects of the device used to prevent sows from crushing piglets correspond to those of the methods described above. Therefore, the beneficial effects of the device will not be elaborated here.
[0114] Figure 5 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 5 As shown, the electronic device may include: a processor 510, a communications interface 520, a memory 530, and a communications bus 540, wherein the processor 510, the communications interface 520, and the memory 530 communicate with each other through the communications bus 540. The processor 510 can call logic instructions in the memory 530 to execute a method for preventing a sow from crushing piglets. This method includes: acquiring a first real-time image of the sow and piglets; performing position detection on the piglets based on the first real-time image; and performing a first posture detection on the sow based on the first real-time image. When the result of the first posture detection indicates that the sow is about to lie down in the area below her body, and the position detection result is within the area below her body, intervention is triggered on the sow's posture, and the piglets are marked as being in a dangerous state. Based on a second real-time image of the sow and the piglets marked as being in a dangerous state, a second posture detection is performed on the sow. When the result of the second posture detection indicates that the sow is still about to lie down in the area below her body, the second real-time image is segmented to obtain the sow's body coverage area and the target area of the piglets marked as being in a dangerous state. When the body coverage area covers the target area, and the target area does not move within a preset time period, an alarm is triggered.
[0115] Furthermore, the logical instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0116] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the methods provided above for preventing sows from crushing piglets. The method includes: acquiring a first real-time image of the sow and piglets; performing position detection on the piglets based on the first real-time image; and performing a first posture detection on the sow based on the first real-time image; when the result of the first posture detection indicates that the sow is about to lie down in the area under her body, and the result of the position detection is within the area under her body, triggering intervention on the sow's posture and marking the piglets as dangerous; performing a second posture detection on the sow based on a second real-time image of the sow and the piglets marked as dangerous; when the result of the second posture detection indicates that the sow is still about to lie down in the area under her body, segmenting the second real-time image to obtain the body-covered area of the sow and the target area of the piglets marked as dangerous; and triggering an alarm when the body-covered area covers the target area and the target area does not move within a preset time period.
[0117] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements a method for preventing sows from crushing piglets, as provided by the methods described above. The method includes: acquiring a first real-time image of the sow and piglets; performing position detection on the piglets based on the first real-time image; and performing a first posture detection on the sow based on the first real-time image; when the result of the first posture detection indicates that the sow is about to lie down in the area below her body, and the result of the position detection is within the area below her body, triggering intervention on the sow's posture and marking the piglets as dangerous; performing a second posture detection on the sow based on a second real-time image of the sow and the piglets marked as dangerous; when the result of the second posture detection indicates that the sow is still about to lie down in the area below her body, segmenting the second real-time image to obtain the body-covered area of the sow and the target area of the piglets marked as dangerous; and triggering an alarm when the body-covered area covers the target area and the target area does not move within a preset time period.
[0118] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0119] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0120] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for preventing sows from crushing piglets, characterized in that, include: Acquire first real-time images of the sow and piglets, perform position detection on the piglets based on the first real-time images, and perform first pose detection on the sow based on the first real-time images; When the result of the first posture detection indicates that the sow is about to lie down in the area below her body, and the position detection result is in the area below her body, an intervention is triggered on the sow's posture, and the piglets are marked as being in a dangerous state. Based on the second real-time images of the sow and piglets marked as dangerous, a second pose detection is performed on the sow. When the result of the second pose detection indicates that the sow still wants to lie down in the area under her body, the second real-time image is segmented to obtain the body coverage area of the sow and the target area of the piglets marked as dangerous. An alarm is triggered when the body coverage area covers the target area and the target area does not move within a preset time period.
2. The method for preventing sows from crushing piglets according to claim 1, characterized in that, The step of detecting the piglet's location based on the first real-time image includes: The YOLOv11 model is invoked to perform first target detection on each frame of the target image in the first real-time image, thereby obtaining the first target position of each piglet in the target image; For each piglet, a target tracking algorithm is invoked to predict the movement trend of the first target position, thereby obtaining the piglet's movement trajectory.
3. The method for preventing sows from crushing piglets according to claim 1, characterized in that, The step of detecting the first pose of the sow based on the first real-time image includes: Based on each frame of the target image in the first real-time image, skeletal key points of the sow are detected to obtain multiple skeletal key points of the sow at the elbow joint of the forelimb. Based on the skeletal key points, construct the limb segment vector of the sow's forelimb elbow joint in the target image, and calculate the angle between the limb segment vectors; When the included angle is less than the angle threshold, it is determined that the sow is in a position where she is about to lie down in the area below her body; or, For each frame of the target image in the first real-time image, determine the height of the highest point of the sow's back or the lowest point of her abdomen from the ground; For two target images with adjacent frame numbers in the first real-time image, calculate the rate of change of the height value; When the rate of change is greater than the rate threshold, it is determined that the sow is in a position where she will lie down in the area under her body.
4. The method for preventing sows from crushing piglets according to claim 1, characterized in that, The triggering of intervention in the sow's posture includes: A first intervention command is sent to an intervention device located on the sow's leg. The first intervention command is used to trigger the intervention device to generate a first low-frequency electrical pulse signal to perform a first stimulation on the sow's leg. One second after the first stimulus is delivered, the sow's third posture is detected using the first real-time image; When the result of the third posture detection indicates that the sow still wants to lie down in the area under her body, a second intervention command is sent to the intervention device. The second intervention command is used to trigger the intervention device to generate a second low-frequency electrical pulse signal to perform a second stimulus on the sow's legs. The amplitude of the second low-frequency electrical pulse signal is greater than the amplitude of the first low-frequency electrical pulse signal.
5. The method for preventing sows from crushing piglets according to claim 1, characterized in that, The step of detecting the piglet's position based on the first real-time image is implemented by calling an object detection model, and the step of detecting the sow's first pose based on the first real-time image is implemented by calling a pose estimation model. The training process of the object detection model includes: Obtain an image dataset of sows and piglets during their activities, wherein each training image in the image dataset is marked with the true location of the sow's skeletal key points and the true bounding box of the piglet; The image dataset is input into the object detection model for forward propagation to obtain the predicted bounding box of the piglets; A multi-task loss function is constructed based on the ground truth bounding box and the predicted bounding box, and then backpropagated through the multi-task loss function in the object detection model to update the parameters of the object detection model. The training process of the pose estimation model includes: The image dataset is input into the pose estimation model for forward propagation to obtain the predicted locations of the skeletal key points of the sow; A mean squared error loss function is constructed based on the predicted position and the actual position, and then backpropagated through the mean squared error loss function in the attitude estimation model to update the parameters of the attitude estimation model.
6. The method for preventing sows from crushing piglets according to claim 1, characterized in that, The method further includes: In the second real-time image, two target images whose shooting time interval exceeds a preset time period are identified; If the target region is in the same position or size in the two target images, then it is determined that the target region has not moved within the preset time period.
7. A device for preventing sows from crushing piglets, characterized in that, include: The surveillance camera, edge device, stimulation device, and alarm, wherein the edge device includes a detection module, a triggering module, and a processing module; The detection module is used to acquire a first real-time image of the sow and piglets through the monitoring camera, perform position detection on the piglets based on the first real-time image, and perform a first posture detection on the sow based on the first real-time image. The triggering module is used to trigger the stimulation device to intervene in the sow's posture and mark the piglets as dangerous when the result of the first posture detection indicates that the sow is about to lie down in the area below her body and the result of the position detection is in the area below her body. The processing module is used to perform a second pose detection on the sow after intervention based on the second real-time images of the sow and piglets marked as being in a dangerous state; When the result of the second posture detection indicates that the sow still lies down in the area under her body after intervention, the second real-time image is segmented to obtain the sow's body coverage area and the target area of the piglets marked as dangerous. The triggering module is also used to trigger the alarm when the body coverage area covers the target area and the target area does not move within a preset time period.
8. The device for preventing sows from crushing piglets according to claim 7, characterized in that, The stimulation device includes: a lithium battery, a discharge drive board, a safety protection device, and a communication device. The lithium battery is used to power the discharge drive board, the safety protection device, and the communication device. The communication device is used to communicate with the edge device via the network, and when it receives an intervention command sent by the edge device, it triggers the discharge drive board to output a low-frequency electrical pulse signal. The safety protection device is used to cut off the power supply from the lithium battery to the discharge drive board when the current, temperature, or output time of the low-frequency electrical pulse signal output by the discharge drive board reaches a corresponding threshold.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the method for preventing sows from crushing piglets as described in any one of claims 1 to 6.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method for preventing sows from crushing piglets as described in any one of claims 1 to 6.