Method for calculating the activity of a lactating piglet
By employing multi-target tracking technology and deep learning algorithms, the problem of monitoring the leg strength of suckling piglets has been solved, enabling rapid and accurate calculation of piglet activity and movement speed, and supporting welfare-oriented farming and smart animal husbandry applications.
Patent Information
- Application Number
- CN202411852031.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2044-12-16
AI Technical Summary
In large-scale commercial pig farms, existing technologies are insufficient for quickly and accurately monitoring the leg health of suckling piglets. Furthermore, existing methods are time-consuming, labor-intensive, and costly, failing to meet the needs of welfare-oriented farming and precision animal husbandry.
By combining multi-target tracking technology with deep learning algorithms, video data is collected through a camera, the YOLO_v8 target detection model is trained, a multi-target tracking model is designed, and Kalman filter and Hungarian algorithm are used for target matching to calculate the movement trajectory and activity level of piglets.
It enables rapid and accurate tracking and identification of piglets in complex farrowing environments, calculates their activity levels and movement speed, and supports the assessment of the health status of lactating piglets in the fields of precision farming and smart animal husbandry.
Smart Images

Figure CN119785381B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of intelligent pig breeding, and particularly relates to a method for positioning and tracking lactating piglets by using deep learning technology and multi-target tracking technology and calculating activity amount according to a movement track of the piglets. BACKGROUND
[0002] In a large-scale commercial pig farm, in order to reduce the probability of newborn piglets being crushed to death by postpartum sows, a limiting stall is usually used to limit the parturient sow before and after the sow gives birth. However, when the piglets have a certain leg robustness so as to be able to avoid the crushing of the sow, in order to improve the welfare level of the sow and ensure the health status of the sow during lactation, the limiting stall should be opened to allow the sow to move freely.
[0003] At present, the monitoring of the robustness of the lactating piglets mainly depends on artificial observation and the experience judgment of the feeders, which is not only time-consuming and labor-consuming and low in efficiency, but also may have observation deviation. With the development of radio frequency identification technology, some large-scale pig farms determine the identity of the piglets by means of electronic ear tags and track the targets to obtain the movement information of the targets, but the installation of the electronic ear tags may cause a short-term stress reaction of the piglets, and the identity of the target needs to be identified by means of an external reader, which is high in economic cost. The implantable device still has some problems, so under the synchronous driving of the welfare breeding concept and the demand of the precise livestock breeding industry, it has important practical significance to use the computer vision technology to automatically track the piglets in a low-cost and non-contact manner and evaluate the leg robustness of the piglets. The daily movement of the piglets under natural conditions is an important basis for analyzing the leg robustness of the piglets, and kinematics shows that the piglets with poor leg robustness are likely to have problems such as low walking speed for a long time, short walking stride and long standing time. Therefore, it is very important to propose a method for positioning and tracking lactating piglets by using multi-target tracking technology and calculating the activity amount and movement speed of the piglets according to the movement track of the piglets, which is the basis for measuring the leg robustness of the piglets. SUMMARY
[0004] The calculation of the activity amount and movement speed of the piglets is the basis for measuring the leg robustness of the piglets. A method for detecting and tracking the piglets in a complex delivery bed environment is needed to obtain the position information and movement track of the piglets and calculate the activity amount and movement speed of the individual piglets and the group piglets. The present application aims to solve the problem of how to use multi-target tracking technology to position and track the piglets and calculate the activity amount of the piglets.
[0005] TECHNICAL SCHEME
[0006] To solve the above problems, the present application proposes a method for positioning and tracking lactating piglets by using multi-target tracking technology and calculating the activity amount and movement speed of the piglets according to the movement track of the piglets, which specifically comprises the following steps:
[0007] S1, collecting pig delivery bed video data and preprocessing the data at the pig farm on the day of farrowing to 28 days after farrowing;
[0008] S1-1, collecting activity video of piglets on the pig delivery bed with a camera at a top-down perspective;
[0009] S1-2, frame, clean, filter, denoise, image enhancement and other operations are performed on the collected piglet video to construct a piglet image dataset D1;
[0010] S1-3, intercepting piglet video clips to construct a piglet video dataset D2;
[0011] S2, training a target detection deep learning model YOLO_v8 to obtain a lactation piglet target detection box;
[0012] S2-1, dividing the piglet image dataset D obtained in step S1 into a training set D1_train, a validation set D1_valid and a test set D1_test according to a ratio of 8:1:1;
[0013] S2-2, performing piglet individual target box labeling on the training set D1_train, the validation set D1_valid and the test set D1_test respectively, drawing a rectangular bounding box for each piglet in the piglet image, and marking the position of the piglet;
[0014] S2-3, generating a corresponding image name txt file for each labeled image file, containing target category, labeling box upper left corner coordinates (x GT , y GT ), labeling box width w GT and labeling box height h GT , wherein x GT , y GT , w GT , h GT are normalized values;
[0015] S2-4, selecting a YOLO_v8 model to train the labeled training set D1_train, and using the validation set D1_valid for validation to obtain a piglet target detection model;
[0016] S2-5, inputting the test set D1_test divided in S2-2 into the trained piglet target detection model to evaluate the performance indicators of the model;
[0017] S2-6, using the trained piglet target detection model to identify the video frame to obtain the upper left corner coordinates (x tl , y tl), the width w and the height h of the detection box, to obtain the center point coordinates (x center , y center ) of the piglet target detection box.
[0018] S3, designing a multi-target tracking model, associating the track and the detection.
[0019] S3-1, using a Kalman filter to estimate the target position and motion state.
[0020] S3-2, using Complete IoU Loss, i.e. CIoU, to calculate the position similarity between the detection box and the track prediction box, to generate a similarity matrix M of the detection and the track.
[0021] S3-3, using the Hungarian algorithm to match the detection and the track according to the similarity matrix M, to assign an ID number to the target, and to form multiple tracking tracks.
[0022] S4, selecting a piglet video from the data set D2 to input the target detection model and the multi-target tracking model, to obtain the position and the motion track of the piglet target.
[0023] S4-1, inputting the piglet video frame by frame to the trained YOLO_v8 target detection model, to obtain the target detection result, including the piglet target position and the confidence information.
[0024] S4-2, inputting the detection result to the multi-target tracking model, to assign a unique identity number to the piglet individual.
[0025] S4-3, repeating steps S4-1 and S4-2 in the subsequent frames until the video ends, to output the target tracking result to a txt file, including the frame number, the piglet target identity number and the piglet target position information.
[0026] S5, calculating the piglet activity and the motion speed according to the motion track.
[0027] S5-1, reading the target tracking result txt file, according to the frame number t, the piglet target identity number i, the piglet target center point coordinates u, v.
[0028] S5-2, calculating the total activity s i of a single piglet in the video and the total activity S of all piglets.
[0029] S5-3, calculating the motion speed p i of a single piglet in the video and the average motion speed P of all piglets in the video.
[0030] Advantages of the present application
[0031] The application applies a multi-target tracking algorithm to tracking of piglets, realizes determination of individual identification and tracking of piglets in a complex farrowing bed environment, and calculates activity and movement speed according to a movement trajectory of the piglets. The disclosed technology provides technical support for welfare-type farrowing bed environment-based measurement of leg robustness of piglets during lactation, and can help pig breeders quickly and accurately master the activity level and health condition of piglets, and has a wide application prospect in the field of precision breeding and intelligent animal husbandry. BRIEF DESCRIPTION OF DRAWINGS
[0032] Figure 1 A whole flowchart of a method for calculating activity of piglets during lactation based on multi-target tracking according to the application.
[0033] Figure 2 A flowchart of a multi-target tracking algorithm according to the application.
[0034] Figure 3 A partial parameter diagram of Complete IoU Loss according to the application.
[0035] Figure 4 A multi-target tracking model result visualization diagram according to the application (respectively, the 0th frame, 100th frame, 200th frame, 300th frame, 400th frame and 500th frame of a test video). DETAILED DESCRIPTION
[0036] The application will be further described below in combination with the drawings and examples. In the embodiment of the application, a method for positioning and tracking piglets during lactation by using multi-target tracking technology and calculating activity and movement speed according to a movement trajectory of the piglets is provided. The method collects video data in the field and performs preprocessing, uses a deep learning algorithm to obtain a piglet detection frame, obtains a movement trajectory of the piglet by using a multi-target tracking model, and calculates activity and movement speed of the piglet. The whole flowchart of the method is shown in Figure 1 The method mainly includes the following steps (S1 to S4):
[0037] S1, collecting pig farrowing bed video data in a pig farm from the day after parturition of a sow to 28 days after parturition and preprocessing the data;
[0038] S1-1, collecting activity video of piglets on a pig farrowing bed by using a camera at a top-down perspective;
[0039] S1-2, performing frame division, cleaning, screening, noise reduction, image enhancement and other operations on the collected piglet video, and constructing a piglet image data set D1;
[0040] S1-3, intercepting a piglet video segment, and constructing a piglet video data set D2;
[0041] S2, train the target detection deep learning model YOLO_v8 to obtain the target detection frame of the lactating piglet;
[0042] S2-1, divide the piglet image dataset D obtained in step S1 into a training set D1_train, a validation set D1_valid and a test set D1_test according to a ratio of 8:1:1;
[0043] S2-2, perform piglet individual target frame labeling on the training set D1_train, the validation set D1_valid and the test set D1_test respectively, draw a rectangular boundary frame for each piglet in the piglet image, and mark the position of the piglet with the class piglet;
[0044] S2-3, generate a corresponding image name txt file for each labeled image file, which contains the target class, the coordinates (x GT , y GT ) of the upper left corner of the labeling frame, the width w GT and the height h GT of the labeling frame, wherein x GT , y GT , w GT , h GT are normalized values;
[0045] S2-4, select the YOLO_v8 model to train the labeled training set D1_train, and use the validation set D1_valid for validation to obtain a piglet target detection model;
[0046] S2-5, input the test set D1_test divided in S2-2 into the trained piglet target detection model, and evaluate the performance indicators of the model;
[0047] S2-6, use the trained piglet target detection model to identify the video frame, obtain the upper left corner coordinates (x tl , y tl ) of the target detection frame of the lactating piglet in the video frame, the width w and the height h of the detection frame, calculate the center point coordinates (x center , y center ) of the piglet target detection frame, and the calculation formula is as follows:
[0048]
[0049] S3, design a multi-target tracking model to associate the track and the detection; in combination with Figure 2 , specifically including:
[0050] S3-1, use a Kalman filter to estimate the next frame target position and motion state;
[0051] S3-2, calculate the position similarity between the detection frame and the track prediction frame using Complete IoU Loss, i.e., CIoU, generate a similarity matrix M between the detection and the track, and the CIoU calculation formula is as follows:
[0052]
[0053] As shown in the formula, d is the distance between the center points of the prediction frame and the detection frame, c is the diagonal distance of the minimum circumscribed rectangle of the prediction frame and the detection frame, and the correction factor Figure 3 Positive trade-off parameter
[0054] S3-3, match the detection and the track according to the similarity matrix M using the Hungarian algorithm, assign an ID number to the target, and form multiple tracking tracks;
[0055] S4, select the piglet video from the data set D2 and input the target detection model and the multi-target tracking model to obtain the position and motion track of the piglet target;
[0056] S4-1, input the piglet video frame by frame into the trained YOLO_v8 target detection model to obtain the target detection result, which includes the piglet target position and confidence information;
[0057] S4-2, input the detection result into the multi-target tracking model to assign a unique identity number to the piglet individual;
[0058] S4-3, repeat steps S4-1 and S4-2 in subsequent frames until the video ends, and output the target tracking result to a txt file, including the frame number, the piglet target identity number and the piglet target position information;
[0059] The multi-target tracking model result visualization of the application is shown in Figure 4 (0th frame, 100th frame, 200th frame, 300th frame, 400th frame and 500th frame of the test video, respectively).
[0060] S5, calculate the piglet activity and motion speed according to the motion track;
[0061] S5-1, read the target tracking result txt file, and according to the frame number t, the piglet target identity number i, the piglet target center point coordinates u, v;
[0062] S5-2, calculate the total activity s of a single piglet in the video i , and the calculation formula is as follows:
[0063]
[0064] Where T represents the total number of video frames,
[0065] The total activity S of all piglets is calculated, and the calculation formula is as follows:
[0066]
[0067] Wherein, n is the total number of piglets in the video;
[0068] S5-3, the movement speed of a single piglet in the video and the average movement speed of all piglets in the video are calculated, the movement speed of a single piglet in the video p i , the calculation formula is as follows:
[0069]
[0070] The average movement speed P of all piglets in the video is calculated, and the calculation formula is as follows:
[0071]
[0072] Preferably, the embodiment uses YOLO_v8 as the target detection algorithm, and other target detection algorithms can also be used, including but not limited to YOLO_v5, YOLO_v10, YOLOX and RT-DETR, etc. The present embodiment compares and selects the optimal scheme according to the existing data.
[0073] Preferably, the embodiment uses Kalman filter and Hungarian algorithm to complete the association operation of the multi-target tracking algorithm, and other modules and algorithms can also be used. The present embodiment compares and selects the optimal scheme according to the existing data.
[0074] The embodiments of the application are described above in combination with the drawings, but the application is not limited to the above specific embodiments, and the above specific embodiments are only illustrative, not restrictive, and those skilled in the art can make many forms under the inspiration of the application without departing from the scope of the application and the scope protected by the claims.
Claims
1. A method for calculating the activity level of lactating piglets, characterized in that It includes the following steps S1 to S5: S1. Collect image data of piglets on a farrowing bed and preprocess the image data to obtain a piglet image dataset D1; S2. Obtain the optimal target detection deep learning model YOLO_v8; specifically including: S2-1, divide the piglet image dataset D1 into a training set D1_train, a validation set D1_valid, and a test set D1_test; S2-2. Label the individual piglet target boxes for the training set D1_train, the validation set D1_valid, and the test set D1_test. Draw a rectangular bounding box for each piglet in the piglet image, with the class piglet, and mark the location of the piglet. S2-3, generate a txt file with the corresponding image name for each labeled image file, including the target category, the coordinates of the upper left corner of the annotation box (x GT ,y GT ), the width of the annotation box is w GT and the height of the label box h GT , where x GT 、y GT 、w GT 、h GT All are normalized values; S2-4. Use the YOLO_v8 model to train the labeled training set D1_train and use the validation set D1_valid for verification to obtain the piglet target detection model. S2-5. Input the test set D1_test divided in S2-2 into the trained piglet target detection model, evaluate the performance indicators of this model, and obtain the optimal target detection deep learning model YOLO_v8; S2-6, based on the optimal target detection deep learning model YOLO_v8, the input is the image data of the piglet, and the output is the coordinates of the upper left corner of the piglet target detection box (x tl ,y tl ), the width w and height h of the detection frame; calculate the center point coordinates (x center ,y center ); S3. Design a multi-target tracking model, associating trajectories and detections; S4. Obtain video data of the piglets to be calculated, input the optimal target detection deep learning model YOLO_v8 and the multi-target tracking model frame by frame, and obtain the position and motion trajectory of the piglet target in each frame; S5. Calculate the piglet's activity level and movement speed based on the movement trajectory.
2. The method according to claim 1, characterized in that In step S1, the image data is obtained by the following steps: S1-1. Use a camera to collect video data of farrowing beds used by sows from the day after farrowing to 28 days after farrowing in the pig farm; S1-2. Divide the collected piglet video data into frames to obtain piglet image data.
3. The method according to claim 1, characterized in that In step S1, the preprocessing includes cleaning, screening, noise reduction, and image enhancement operations.
4. The method according to claim 1, characterized in that In step S2-6, the center point coordinates (x center ,y center ) is calculated as follows: Where: x center ,y center are the horizontal and vertical coordinates of the center point, respectively, tl ,y tl are the horizontal and vertical coordinates of the upper left corner of the target detection box respectively.
5. The method according to claim 1, characterized in that The step S3 specifically includes: S3-1, use Kalman filter to estimate the target position and motion state of the next frame; S3-2. Use CIoU to calculate the position similarity between the detection box and the trajectory prediction box, and generate a detection and trajectory similarity matrix M, where the rows of M represent the index of the detection box and the columns of M represent the index of the trajectory prediction box; S3-3. Use the Hungarian algorithm to match detections and trajectories based on the similarity matrix M, assign ID numbers to targets, and form multiple tracking trajectories.
6. The method according to claim 5, characterized in that In step S3-2, the CIoU calculation formula is as follows: Where d is the distance between the center points of the predicted box and the detection box, c is the diagonal distance between the minimum circumscribed rectangle of the predicted box and the detection box, and IoU is the intersection over union of the predicted box and the true box. CIoU uses the correction factor v to measure the aspect ratio of the real box and the predicted box aspect ratio The similarity of the correction factor v is calculated as follows: The positive trade-off parameter α is calculated as follows:
7. The method according to claim 1, characterized in that The step S4 specifically includes: S4-1. Input the piglet video frame by frame into the optimal target detection deep learning model YOLO_v8 to obtain the target detection results, including the piglet target location and confidence information; S4-2, inputting the detection results into a multi-target tracking model and assigning a unique identification number to each piglet; S4-3. Repeat steps S4-1 and S4-2 in subsequent frames until the end of the video, and output the target tracking results to a txt file, including the frame number, piglet target identity number and piglet target position information.
8. The method according to claim 1, characterized in that The step S5 specifically includes: S5-1, read the target tracking result txt file, according to the frame number t, the piglet target identity number i, the piglet target center point coordinates u, v; S5-2. Calculate the total activity s of a single piglet in the video i and the total activity level of all piglets, S; S5-3. Calculate the movement speed p of a single piglet in the video i and the average movement speed P of all piglets in the video.
9. The method according to claim 8, characterized in that: Calculate the total activity s of a single piglet in the video i , the calculation formula is as follows: Where T represents the total number of video frames; Calculate the total activity S of all piglets using the following formula: Where n is the total number of piglets in the video.
10. The method according to claim 8, characterized in that: The movement speed p of a single piglet in the video i , the calculation formula is as follows: The average movement speed P of all piglets in the video is calculated as follows: