A multi-target tracking method for suckling piglets based on self-attention mechanism

By introducing the BotNet network model of the self-attention mechanism and the adaptive confidence matching strategy in the TransTrack algorithm, the problem of missed detection and false detection of piglet tracking in the pig farm environment is solved, and the tracking accuracy and stability are improved.

CN114898250BActive Publication Date: 2024-09-06SOUTH CHINA AGRICULTURAL UNIVERSITY
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202210393478.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-15
Publication Date
2024-09-06
Estimated Expiration
2042-04-15

AI Technical Summary

Technical Problem

In the complex environment of the pig farm, especially in the case of dim lighting and occlusion between piglets, it is difficult for the existing technology to effectively track piglets, leading to problems of missed detection and false detection.

Method used

The BotNet network model based on the self-attention mechanism is used, combined with the dark area adaptive confidence matching strategy and the error detection location strategy based on historical frame markers, to improve the TransTrack algorithm, enhance feature extraction capabilities and reduce missed detections and false detections.

Benefits of technology

It improves the accuracy and stability of piglet tracking, effectively reduces missed detections and false detections in dark areas, and ensures ID stability and accuracy during the tracking process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114898250B
    Figure CN114898250B
Patent Text Reader

Abstract

The present invention discloses a method for multi-target tracking of suckling piglets based on a self-attention mechanism, comprising: S1, collecting videos of suckling piglets in a pen, making a data set for multi-target tracking of suckling piglets, and dividing it into a training set and a test set; S2, improving the network model of TransTrack, and training the improved network model with the training set; S3, using the trained network model to output the tracking results of piglet detection and prediction on the test set; S4, designing an adaptive confidence matching strategy for dark areas, and retrieving missed targets in the detection results of dark areas; S5: designing a misdetection position strategy based on historical frame markings to avoid misdetection in the detection results. The present invention solves the problems of misdetection, missed detection and ID exchange of piglets during the tracking process of suckling piglets in the pen, due to insufficient global feature extraction capabilities of piglets, dim lighting, and adhesion and occlusion between piglets and piglets, sows and piglets.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of video multi-target tracking, and in particular to a multi-target tracking method for suckling piglets based on a self-attention mechanism. Background Art

[0002] In the pig farming industry, the health of suckling piglets is an important factor in ensuring the profitability of the farm. Monitoring the movement behavior of piglets is conducive to timely detection of abnormalities and understanding of health conditions. When monitoring pig behavior, the main method is manual observation, which is too subjective and time-consuming. The suckling piglet behavior recognition method based on computer vision only requires the installation of cameras in the pig farm and the analysis of the piglet behavior in the video through intelligent algorithms to replace manual observation. For piglet behavior recognition, multi-target tracking is the key foundation.

[0003] Among the current pig tracking methods, patent publication number CN105913425A extracts multiple pig contours based on adaptive ellipse block and wavelet transform, and then tracks them. Patent publication number CN109684953B detects pigs using algorithms such as background difference and threshold segmentation, and then uses a particle filter algorithm for tracking prediction. Patent publication number CN113763429A uses YOLOv3 to detect the target position of pigs, and performs multi-target pig tracking based on DeepSort.

[0004] In the pigpen environment of the pig farm, the lighting conditions are complex, and there are adhesions and occlusions between sows and piglets, and between piglets, which will lead to missed detections and false detections in the piglet detection and tracking process. Therefore, based on the TransTrack tracking algorithm, the algorithm network of TransTrack is improved, and the basic network resnet50 is changed to Botnet. An adaptive confidence matching method for dark areas in the pigpen and a method for marking false detection positions based on historical frames are proposed to improve the piglet tracking accuracy in the complex environment of the pig farm. Summary of the invention

[0005] The purpose of the present invention is to address the difficulty in tracking piglets in the complex environment of a pig farm due to dim lighting, occlusion and adhesion between piglets and between piglets and sows, and propose a multi-target tracking method for suckling piglets based on a self-attention mechanism, which can effectively improve the ability of piglet feature extraction, solve the problems of missed detection of piglets in dark areas, and ID swapping or misdetection during the tracking process.

[0006] To achieve the above object, the technical solution provided by the present invention is: a multi-target tracking method for suckling piglets based on a self-attention mechanism, comprising the following steps:

[0007] S1. Collect videos of suckling piglets in pens, create a dataset for multi-target tracking of suckling piglets, and divide the dataset into a training set and a test set; convert the video clips into images according to the frame rate, and use labelme to manually annotate the piglet outlines and corresponding IDs;

[0008] S2. Improve the network model of TransTrack by changing the basic network resnet50 to BotNet with self-attention mechanism to improve the ability of piglet feature extraction. Use the prepared training set to train the improved network model to obtain a trained network model.

[0009] S3, use the test set to test the trained network model, output the detection candidate box of the current frame, and at the same time, track the results of the previous frame t-1 , predict the tracking results of the current frame Tracks t , that is, the detection results and predicted tracking results in the test set are obtained;

[0010] S4. Design an adaptive confidence matching strategy for dark areas, which is used to lower the confidence threshold of the dark area after determining the position of the dark area, and retrieve the missed detection targets in the dark area in the obtained detection results;

[0011] S5. Design a false detection location strategy based on historical frame markings. In the detection results, if the number of IDs is greater than the set piglet number threshold in the pigpen, the IDs greater than the number threshold will be marked as false detections. In the detection results of subsequent frames, the results marked as false detections based on historical markings will be removed to obtain accurate detection results and improve tracking accuracy.

[0012] Further, the specific steps of step S1 are as follows:

[0013] S11, using a camera to collect real-time videos of suckling piglets above the pig pen, selecting daytime video clips, each clip is 30 seconds, a total of 105 clips;

[0014] S12, selecting the video frame rate as 10 frames per second, and the image resolution sizes as 960×540 and 1920×1080 to obtain the final data;

[0015] S13, making the final data into a dataset, including a training set and a test set, converting the video clips into images according to the frame rate, and manually annotating the piglet outlines and corresponding IDs using labelme;

[0016] S14. Convert the prepared data set into the coco data format required for training.

[0017] Further, the specific steps of step S2 are as follows:

[0018] S21. Improve the network model of TransTrack, change the basic network resnet50 of TransTrack to BotNet with self-attention mechanism, enhance the feature extraction effect, capture long-distance dependencies, and take non-adjacent pixels into consideration as a whole;

[0019] Among them, BotNet uses Bot blocks to replace the last three convolution blocks in Resnet50, and replaces the 3×3 convolution in the convolution block with a multi-head self-attention module MHSA, which is expressed as MHSA(Q,K,V)=Concat(head1,head2,...,head n )W O , The Attention calculation formula is: Where Q, K are weight matrices used to calculate attention, V is the weight matrix used to sum the attention weights to get the final result, and d k is the size of the matrix K dimension, through the weight Perform a linear transformation and finally pass the learnable weight matrix W O , multiple heads obtained by Attention n Spliced ​​together, the final multi-head self-attention result value MHSA(Q,K,V) calculated by Q,K,V is obtained, which is used to extract features of the current frame image;

[0020] S22, BotNet extracts feature map F for the current frame image t , and then with the previous frame feature map F t-1 Combine them together and input them into the subsequent encoder;

[0021] S23, output the encoding result of the input encoder to two decoders, the detection branch and the tracking branch, to obtain a detection frame and a tracking frame respectively;

[0022] S24, the detection box and the tracking box are both regarded as the target detection box of the current frame, so the two decoders can be trained simultaneously with the same training loss; the GPU is used to accelerate the training of the improved network model under the Pytorch deep learning framework. During the training process, two consecutive frames are used as training samples, and the one with the lowest loss during the training of the improved network model is selected as the network model for subsequent use.

[0023] Further, in step S4, a dark area adaptive confidence matching strategy is designed, and the specific steps are as follows:

[0024] S41, firstly, a sliding window method is used to determine the location of the dark area; the window size is w=100 pixels in width and h=1920 or 960 pixels in height as the video frame height, and the pixel values ​​of the three channels R, G, and B of each pixel point in the window are summed. When the number of pixel points whose sum value is less than 150 is greater than a specified threshold value T=50*h / 3, the area in the window is regarded as a dark area;

[0025] S42, after obtaining the detection candidate boxes, first add the ones with confidence greater than 0.7 as the detection results to the detection results Dets; add all the candidate boxes with confidence less than 0.7 and greater than 0.1 in the detection candidate boxes to the pending result U_det, and judge whether each candidate box in U_det is in the dark area. For the candidate boxes in the dark area, proceed to the next step of judgment, and the candidate boxes not in the dark area are abandoned;

[0026] S43, in order to avoid introducing false detection when supplementing missed detection, calculate U_det and the tracking result Tracks of the previous frame t-1 The intersection of the two is iou1. If iou1 is less than 0.8, the candidate box is abandoned. If iou1 is greater than 0.8, the iou2 of U_det and Dets is calculated. If iou2 is less than 0.9, the candidate box in U_det is added to Dets, that is, the missed part of the dark area is added to the detection result, and the candidate boxes in Dets are regarded as detection boxes, and the candidate boxes in U_det with iou2 greater than 0.9 are abandoned.

[0027] Further, in step S5, the designed error detection location strategy based on historical frame marking has the following specific steps:

[0028] S51, compare the detection box in the detection result Dets of step S4 with the tracking result Tracks of the current frame t The tracking box in the calculation of IOU, using Hungarian matching, assigns an ID;

[0029] S52. In the pig pen environment, the number of piglets is fixed. Therefore, in order to avoid unnecessary false detection during the tracking process, when adding a new pig ID, it is compared with the number threshold Num; if it is less than the threshold, a new ID is assigned; if it is greater than the threshold, it is considered that all pigs already have IDs at this time, and no more IDs should be assigned to avoid false detection or ID swapping;

[0030] S53. On the basis of being greater than the threshold, mark the false detection: when no new id is assigned, the id greater than the threshold will not be directly discarded, but the id will be marked as a false detection result and added to the false detection result set Non_id; in subsequent frames, when Dets is less than Num and false detection cannot be limited, calculate the intersection of the two detection boxes in Dets and Non_id. If giou1 is greater than 1.2, it is regarded as a correct detection box; if giou1 is less than 1.2, it is judged that the detection box in Dets should be a false detection, and the detection box is removed from Dets, thereby limiting the false detection results to occupy the id in the process of allocating ids.

[0031] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0032] 1. The present invention improves the network model based on Transtrack and introduces BotNet with self-attention mechanism to enhance the local and global feature extraction capabilities of piglet images.

[0033] 2. The network model’s ability to distinguish low-confidence candidate boxes during the detection process is enhanced, effectively reducing false detections.

[0034] 3. The size of the improved network model is 508.3MB, and the size of the original network model is 564.4MB. The network size is reduced while the tracking effect is improved.

[0035] 4. To prevent missed detections in dark areas, an adaptive confidence matching strategy for dark areas is added to screen low-confidence candidate frames in dark areas to obtain results that meet the specified conditions, effectively reducing missed detections in dark areas during tracking.

[0036] 5. During the tracking process, the number of piglets in the pig pen is used to limit the number of new IDs, prevent the increase of IDs caused by false detection of video frames during tracking, and ensure the stability of IDs during tracking.

[0037] 6. Add a false detection location strategy based on historical frame marking. Mark the false detection on the basis of restricting the ID. When detecting again in subsequent frames, abandon the marked false detection, overcome the ID preemption phenomenon caused by false detection of video frames during tracking, and improve tracking accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 is a flow chart of the method of the present invention.

[0039] Figure 2 It is a framework diagram of the method of the present invention.

[0040] Figure 3 It is a strategy flow chart of missed detection in dark areas and misdetection of marks designed by the present invention.

[0041] Figure 4 This is the result of capturing the video frames of the two clips. DETAILED DESCRIPTION

[0042] The present invention is further described in detail below in conjunction with embodiments and drawings, but the embodiments of the present invention are not limited thereto.

[0043] In order to overcome the poor lighting conditions in the piglet activity area in a fixed scene, irregular movements, and frequent occlusions between sows and piglets, which lead to unstable numbers in the tracking and statistical process, making identity exchange, false detection and missed detection difficult, this embodiment provides a multi-target tracking method for suckling piglets based on a self-attention mechanism, improves the network model of TransTrack, replaces the basic network resnet50 with a BotNet with a self-attention mechanism, an adaptive confidence matching strategy in dark areas, and a false detection position strategy based on historical frame markings, and uses a greedy algorithm and a Hungarian algorithm based on the detection results and the tracking results of the previous frame to achieve multi-target tracking of piglets, laying a foundation for later piglet behavior research.

[0044] See also Figure 1 As shown in the figure, the method was developed based on the Ubuntu 16.04 operating system and trained using the Nvidia GeForce RTX 3090Ti GPU on the Pytorch deep learning framework platform. The network model of TransTrack was improved and then trained and tested. An adaptive confidence matching strategy for dark areas and a misdetected position strategy based on historical frame markings were designed to complete automatic detection of suckling piglets and perform multi-target tracking.

[0045] The specific implementation steps are:

[0046] Step 1: Collect videos of suckling piglets in the pen, create a dataset for multi-target tracking of suckling piglets, and divide the dataset into a training set and a test set, including the following steps:

[0047] 1) Use a camera to collect real-time videos of suckling piglets directly above the pig pen, select daytime video clips, and select 11 piglets for the experiment. Cut each video to a duration of 30 seconds. The video frame rate is uniformly adjusted to 10 frames per second, and the image resolution is 1920×1080 and 960×540 respectively.

[0048] 2) 8 out of 11 piglet pens were selected as training sets and 3 as test sets. To ensure the applicability of the model in a variety of situations, the selected video clips included piglets in dark and bright light areas, piglets interacting with sows, piglets fighting with piglets, piglets walking, sleeping, etc. After the selection was completed, there were 75 clips in the training set and 30 clips in the test set.

[0049] 3) The video data was processed into a continuous static sequence of image data. The piglets were manually labeled frame by frame using the Labelme software. The labeled box surrounded the piglets and labeled the corresponding ID. The piglet IDs of consecutive frames of the video remained unchanged, and the IDs of different video segments were relabeled from 1.

[0050] 4) After the annotation is completed, convert the annotation results in json format to coco format.

[0051] Step 2: See Figure 2 As shown in the figure, the network model of TransTrack is improved, the basic network resnet50 is changed to BotNet with self-attention mechanism, and the improved network model is trained with the prepared training set, as follows:

[0052] 1) Improve the network model of TransTrack by changing the basic network resnet50 of TransTrack to BotNet with self-attention mechanism to enhance the feature extraction effect, capture long-distance dependencies, and take non-adjacent pixels into consideration as a whole.

[0053] Among them, BotNet uses Bot blocks to replace the last three convolution blocks in Resnet50, and replaces the 3×3 convolution in the convolution block with a multi-head self-attention module MHSA, which is expressed as MHSA(Q,K,V)=Concat(head1,head2,...,head n )W O , The Attention calculation formula is: Where Q, K are weight matrices used to calculate attention, V is the weight matrix used to sum the attention weights to get the final result, and d k is the size of the matrix K dimension, through the weight Perform a linear transformation and finally pass the learnable weight matrix W O , multiple heads obtained by Attention n Spliced ​​together, the final multi-head self-attention result value MHSA(Q,K,V) calculated by Q,K,V is obtained, which is used to extract features of the current frame image;

[0054] 2) BotNet extracts the feature map Ft of the current frame image, then combines it with the feature map Ft-1 of the previous frame and inputs it into the subsequent encoder.

[0055] 3) The encoding result of the input encoder is output to the two decoders Decoder of the detection branch and the tracking branch to obtain the detection box and the tracking box respectively.

[0056] 4) Both the detection frame and the tracking frame can be regarded as the target detection frame of the current frame. Therefore, the two decoders can be trained simultaneously with the same training loss. GPU is used to accelerate the training of the improved network model under the Pytorch deep learning framework. Two consecutive frames are used as training samples during the training process. The one with the lowest loss during the training of the improved network model is selected as the network model for subsequent use.

[0057] 5) During model training, the batch size is set to 2, the number of iterations is 180, and the initial learning rate is 2×10 -4 , the learning rate is decreased by a factor of 10 after 50 iterations.

[0058] Step 3: Use the test set to test the trained network model and output the detection candidate box of the current frame; at the same time, according to the tracking result of the previous frame, Tracks t-1 , predict the tracking results of the current frame Tracks t .

[0059] Step 4: If Figure 3 As shown in the figure, an adaptive confidence matching strategy for dark areas is designed. After determining the position of the dark area, the confidence threshold of the dark area is lowered. In the obtained detection results, the missed targets in the dark area are retrieved. The details are as follows:

[0060] 1) First, a sliding window method is used to determine the location of the dark area. The window size is w = 100 pixels wide and h = 1920 or 960 pixels high, and the R, G, and B channel pixel values ​​of each pixel in the window are summed. When the number of pixels with a sum value less than 150 is greater than the specified threshold T = 50*h / 3, the area in the window is considered a dark area.

[0061] 2) After obtaining the candidate detection boxes, first add the boxes with confidence greater than 0.7 as the detection results to the detection results Dets; add the candidate boxes with confidence less than 0.7 and greater than 0.1 in the detection candidate boxes to the pending result U_det, and judge whether the candidate boxes in U_det are in the dark area. If they are in the dark area, proceed to the next step of judgment, and the candidate boxes that are not in the dark area are abandoned;

[0062] 3) In order to avoid false detection when supplementing missed detection, calculate U_det and the tracking result of the previous frame Tracks t-1The intersection of the two is iou1. If iou1 is less than 0.8, the candidate box is abandoned. If iou1 is greater than 0.8, the iou2 of U_det and Dets is calculated. If iou2 is less than 0.9, the candidate box in U_det is added to Dets, that is, the missed detection part of the dark area is added to the detection result, and the candidate boxes in Dets are regarded as detection boxes. Abandon the candidate box with iou2 greater than 0.9 in U_det;

[0063] Step 5: To address the existing misdetection problem, design a misdetection location strategy based on historical frame markings, such as Figure 3 As shown in the figure, in the detection results, if the number of IDs is greater than the set piglet number threshold, the IDs greater than the number threshold are marked as false detections, and the results marked as false detections based on history are removed from the detection results of subsequent frames. The details are as follows:

[0064] 1) Compare the detection box in Dets with the tracking result of the current frame Tracks t The tracking box in the is used to calculate the IOU, use Hungarian matching, and assign an ID.

[0065] 2) In the pig pen environment, the number of piglets is fixed. Therefore, in order to avoid unnecessary false detection during the tracking process, when adding a new pig ID, it is compared with the number threshold Num; if it is less than the threshold, a new ID can be assigned. If it is greater than the threshold, it is considered that all pigs already have IDs and no more IDs should be assigned to avoid false detection or ID swapping;

[0066] 3) On the basis of being greater than the threshold, false detection is marked: when no new id is assigned, ids greater than the threshold will not be directly discarded, but the ids will be marked as false detection results and added to the false detection result set Non_id; in subsequent frames, when Dets is less than Num and false detection cannot be limited, the intersection of the two detection boxes in Dets and Non_id is calculated. If giou1 is greater than 1.2, it is regarded as a correct detection box; if giou1 is less than the threshold 1.2, it is judged that the detection box in Dets should be a false detection, and the detection box is removed from Dets, thereby limiting the false detection results to occupy the id in the process of allocating ids.

[0067] The improved network model is evaluated using the multi-target tracking evaluation code provided by the MOT Challenge. IDF1 and MOTA are the main evaluation indicators of the model tracking performance.

[0068] Tracking results such as Figure 4 As shown in (a), during the tracking process, when the piglet is in a dark area and the original method cannot solve the problem, the present invention can effectively track the piglet. Figure 4As shown in (b), when a piglet temporarily disappears due to adhesion occupancy, resulting in a false detection of an occupied ID, the present invention can also suppress the false detection by marking it, thus solving the false detection problem relatively well. Therefore, the present invention can accurately and stably assign the corresponding ID to each piglet for tracking.

[0069] To illustrate the accuracy and effectiveness of the method of the present invention for multi-target tracking of suckling piglets, the experimental results of the present invention are described in detail below:

[0070] IDF1 and MOTA are the main evaluation indicators in the field of multi-target tracking in computer vision, and their formula definitions are shown in (1)-(2).

[0071]

[0072]

[0073] Among them, TP is the number of piglets correctly detected in the detection, FN is the number of piglets not detected, and FP is the number of backgrounds mistakenly detected as piglets. IDSW represents the number of ID exchanges during piglet tracking, and GT represents the number of correct manually labeled detections. Table 1 compares the multi-target tracking evaluation results of the original TransTrack and the improved network model of TransTrack. As can be seen from Table 1, as expected, the improved network model of TransTrack can effectively reduce the number of false detections and missed detections, and maintain the stability of the tracking trajectory. Therefore, IDF1 is 1.2 percentage points higher than the original TransTrack; MOTA is 1.1 percentage points higher than the original TransTrack.

[0074] Table 1 Comparison of model results

[0075]

[0076] The specific embodiments described above further describe the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A multi-target tracking method for suckling piglets based on self-attention mechanism, characterized in that: The following steps are involved: S1. Collect videos of suckling piglets in pens, create a dataset for multi-target tracking of suckling piglets, and divide the dataset into a training set and a test set; convert the video clips into images according to the frame rate, and use labelme to manually annotate the piglet outlines and corresponding IDs; S2. Improve the network model of TransTrack by changing the basic network resnet50 to BotNet with self-attention mechanism to improve the ability of piglet feature extraction. Use the prepared training set to train the improved network model to obtain a trained network model. S3, use the test set to test the trained network model, output the detection candidate box of the current frame, and at the same time, track the result of the previous frame. t-1 , predict the tracking results of the current frame Tracks t , that is, the detection results and predicted tracking results in the test set are obtained; S4. Design an adaptive confidence matching strategy for dark areas, which is used to lower the confidence threshold of the dark area after determining the position of the dark area, and retrieve the missed detection targets in the dark area in the obtained detection results; S5. Design a false detection location strategy based on historical frame markings. In the detection results, if the number of IDs is greater than the set piglet number threshold in the pigpen, the IDs greater than the number threshold will be marked as false detections. In the detection results of subsequent frames, the results marked as false detections based on historical markings will be removed to obtain accurate detection results and improve tracking accuracy.

2. A method for tracking multiple targets of suckling piglets based on self-attention mechanism according to claim 1, characterized in that: The specific steps of step S1 are as follows: S11, using a camera to collect real-time videos of suckling piglets above the pig pen, selecting daytime video clips, each clip is 30 seconds, a total of 105 clips; S12, select the video frame rate as 10 frames per second, and the image resolution sizes as 960×540 and 1920×1080 respectively, to obtain the final data; S13, making the final data into a dataset, including a training set and a test set, converting the video clips into images according to the frame rate, and manually annotating the piglet outlines and corresponding IDs using labelme; S14. Convert the prepared data set into the coco data format required for training.

3. The method for multi-target tracking of suckling piglets based on self-attention mechanism according to claim 1, characterized in that: The specific steps of step S2 are as follows: S21. Improve the network model of TransTrack, change the basic network resnet50 of TransTrack to BotNet with self-attention mechanism, enhance the feature extraction effect, capture long-distance dependencies, and take non-adjacent pixels into consideration as a whole; Among them, BotNet uses Bot blocks to replace the last three convolution blocks in Resnet50, and replaces the 3×3 convolution in the convolution block with a multi-head self-attention module MHSA, which is expressed as MHSA(Q,K,V)=Concat(head1,head2,...,head n )W O , The Attention calculation formula is: Where Q, K are weight matrices used to calculate attention, V is the weight matrix used to weight the attention and sum it to get the final result, d k is the size of the matrix K dimension, through the weight Perform a linear transformation and finally pass the learnable weight matrix W O , multiple heads obtained by Attention n Spliced ​​together, the final multi-head self-attention result value MHSA(Q,K,V) calculated by Q,K,V is obtained, which is used to extract features of the current frame image; S22, BotNet extracts feature map F for the current frame image t , and then with the previous frame feature map F t-1 Combine them together and input them into the subsequent encoder; S23, output the encoding result of the input encoder to two decoders, the detection branch and the tracking branch, to obtain a detection frame and a tracking frame respectively; S24, the detection box and the tracking box are both regarded as the target detection box of the current frame, so the two decoders can be trained simultaneously with the same training loss; the GPU is used to accelerate the training of the improved network model under the Pytorch deep learning framework. During the training process, two consecutive frames are used as training samples, and the one with the lowest loss during the training of the improved network model is selected as the network model for subsequent use.

4. The method for multi-target tracking of suckling piglets based on self-attention mechanism according to claim 1, characterized in that: In step S4, the dark area adaptive confidence matching strategy is designed, and the specific steps are as follows: S41, firstly, a sliding window method is used to determine the location of the dark area; the window size is w=100 pixels in width and h=1920 or 960 pixels in height as the video frame height, and the pixel values ​​of the three channels R, G, and B of each pixel point in the window are summed. When the number of pixel points whose sum value is less than 150 is greater than a specified threshold value T=50*h / 3, the area in the window is regarded as a dark area; S42, after obtaining the detection candidate boxes, first add the ones with confidence greater than 0.7 as the detection results to the detection results Dets; add all the candidate boxes with confidence less than 0.7 and greater than 0.1 in the detection candidate boxes to the pending result U_det, and judge whether each candidate box in U_det is in the dark area. For the candidate boxes in the dark area, proceed to the next step of judgment, and the candidate boxes not in the dark area are abandoned; S43, in order to avoid introducing false detection when supplementing missed detection, calculate U_det and the tracking result Tracks of the previous frame t-1 The intersection of the two is iou1. If iou1 is less than 0.8, the candidate box is abandoned. If iou1 is greater than 0.8, the iou2 of U_det and Dets is calculated. If iou2 is less than 0.9, the candidate box in U_det is added to Dets, that is, the missed part of the dark area is added to the detection result, and the candidate boxes in Dets are regarded as detection boxes, and the candidate boxes in U_det with iou2 greater than 0.9 are abandoned.

5. The method for multi-target tracking of suckling piglets based on self-attention mechanism according to claim 1, characterized in that: In step S5, the designed error detection location strategy based on historical frame marking has the following specific steps: S51, compare the detection box in the detection result Dets of step S4 with the tracking result Tracks of the current frame t The tracking box in the calculation of IOU, using Hungarian matching, assigns an ID; S52. In the pig pen environment, the number of piglets is fixed. Therefore, in order to avoid unnecessary false detection during the tracking process, when adding a new pig ID, it is compared with the number threshold Num; if it is less than the threshold, a new ID is assigned; if it is greater than the threshold, it is considered that all pigs already have IDs at this time, and no more IDs should be assigned to avoid false detection or ID swapping; S53, based on the value greater than the threshold, mark the error detection: when no new ID is allocated, the ID greater than the threshold will not be directly discarded, but the ID will be marked as an error detection result and added to the error detection result set Non_id; in the subsequent frame, when Dets is less than Num and the error detection cannot be limited, the intersection and union ratio of each detection box in Dets and Non_id is calculated. 1, If giou1 is greater than 1.2, it is considered a correct detection box; if giou1 is less than 1.2, the detection box in Dets is judged to be a false detection, and the detection box is removed from Dets, thereby limiting the false detection results from occupying the id in the id allocation process.

Citation Information

Patent Citations

  • Self-adaptive oval blocking and wavelet transformation-based multi-pig contour extraction method

    CN105913425A

  • Method and apparatus for pig tracking based on target detection and particle filtering algorithms

    CN109684953B

  • Video-based pig behavior recognition system and method

    CN113763429A

  • Pig face recognition method

    CN111967413A

  • Suckling piglet multi-target tracking method based on long and short memory

    CN113947617A