Behavior recognition method and system for flocked sheep based on target detection and tracking algorithm
Through the YOLOv9c model and the improved ByteTrack algorithm, combined with the time distance matching module and the ID delay allocation mechanism, the problem of sheep only behavior recognition and tracking in sheep farms is solved, and multi-objective tracking and behavior recognition in complex scenarios is realized. Improve the level of refined and intelligent flock management.
Patent Information
- Application Number
- CN202411517483.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2044-10-29
Smart Images

Figure CN119027985B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of agricultural information technology, and in particular relates to a method and system for identifying group-raised sheep behavior based on a target detection and tracking algorithm. Background Art
[0002] Sheep farming is an important part of my country's animal husbandry, and my country's sheep farming industry is developing from individual farming to large-scale and intensive farming. However, with the gradual increase in farming scale and density, the probability of sheep getting sick is also on the rise, and the refined management of sheep has also been greatly challenged. Traditional manual monitoring methods have problems such as difficulty in uninterrupted monitoring, high workload, low efficiency, and high misdiagnosis rate.
[0003] Artificial intelligence technology is rapidly integrating and developing in various fields. Sheep farming is also gradually shifting towards intelligence. Wearable devices based on radio frequency identification technology have achieved certain success in sheep monitoring. However, this method also has certain disadvantages, such as the need to pierce the ears of livestock, which may cause harm to livestock, wearable devices are easy to fall off due to livestock movement, and the cost is high in large-scale farming environments.
[0004] Computer vision technology is widely used in animal monitoring, providing a contactless, automated way to monitor sheep behavior in real time. However, most existing video-based computer vision technologies for sheep monitoring are aimed at counting sheep. In actual large-scale sheep farming scenarios, it is more necessary to monitor sheep behavior and track each sheep in real time to achieve truly refined, unmanned, and intelligent management.
[0005] The living habits of sheep make them often crowded together, resulting in serious long-term occlusion problems. In addition, the sheep's extremely similar appearance characteristics increase the difficulty of target tracking. Summary of the invention
[0006] In order to overcome the deficiencies of the above-mentioned prior art, the present invention provides a method and system for identifying the behavior of group-raised sheep based on target detection and tracking algorithm, which is used to realize real-time multi-target tracking and behavior identification of group-raised sheep through efficient and accurate methods in complex scenarios.
[0007] According to one aspect of the present invention, a method for identifying the behavior of flocked sheep based on a target detection and tracking algorithm is provided, comprising:
[0008] Obtain video data of flocked sheep;
[0009] The acquired video data of the flocked sheep is input into the trained YOLOv9c target detection model to output the location and behavior status information of the sheep;
[0010] Based on the obtained information on sheep location and behavior status, combined with the improved ByteTrack algorithm, all sheep are continuously tracked;
[0011] Among them, the improved ByteTrack algorithm includes: introducing a time distance matching module before creating a new trajectory, and introducing an ID delay allocation mechanism when creating a new trajectory; the introduced time distance matching module is used to combine the long and short time lost trajectory queues to re-match the targets that are lost because the Kalman filter is difficult to predict the position, including: calculating the Euclidean distance between the high-score detection frames and long and short time lost trajectories that have not been successfully matched; calculating the duration of each lost tracking trajectory relative to the current frame; according to the Euclidean distance between the lost trajectory and the detection frame, combined with the trajectory loss duration, calculating the relationship coefficient between the trajectory and the detection frame.
[0012] As a further technical solution, the training of the YOLOv9c target detection model includes:
[0013] Obtain an image dataset of flocked sheep, and label all the sheep in the selected image data to generate a dataset for training;
[0014] Use the labeled dataset to train the YOLOv9c target detection model and obtain the optimal model parameters.
[0015] As a further technical solution, the improved ByteTrack algorithm further includes:
[0016] Design a long and short lost trajectory queue to save short lost trajectories and long lost trajectories;
[0017] A delayed ID allocation mechanism is introduced to delay the allocation of targets after a high-confidence detection box fails to fully match.
[0018] As a further technical solution, an ID delayed allocation mechanism is introduced to delay the allocation of targets after a high-confidence detection box fails to fully match, including:
[0019] When the current frame is the first frame, a new ID and a new track are assigned and the new track is marked as an activated track;
[0020] When the current frame is not the first frame, no new ID is assigned, a new track is assigned and the new track is marked as an inactive track;
[0021] In the stage of matching the inactive track with the detection frame, if the number of consecutive matches of the new track is less than the preset number, the new track is discarded;
[0022] In the stage of matching the inactivated track with the detection frame, when the number of consecutive matches of the new track meets the preset number, a new ID is assigned to the new track and the track is marked as an activated track.
[0023] As a further technical solution, based on the obtained sheep location and behavior status information, combined with the improved ByteTrack algorithm, all sheep are continuously tracked, including:
[0024] Use the non-maximum suppression algorithm to filter out redundant detection boxes, and input the deleted detection results into the improved ByteTrack algorithm;
[0025] The improved ByteTrack algorithm divides the detection frames into two groups: high confidence and low confidence according to the detection frame confidence score. The Kalman filter is used to predict the target position of the next frame. The predicted trajectory is matched with the high-score detection frame for the first IoU, the predicted trajectory is matched with the low-score detection frame for the second IoU, the inactivated trajectory is matched with the high-score detection frame for IoU, and the lost trajectory is matched with the high-score detection frame for time distance.
[0026] Use the Hungarian algorithm to get the first three matching results, get the last matching result according to the time-distance relationship coefficient, and update all trajectory states according to the matching results;
[0027] The Kalman filter is updated and the tracking result is output.
[0028] According to one aspect of the present invention, a group-raising sheep behavior recognition system based on a target detection and tracking algorithm is provided, comprising:
[0029] An input module for acquiring video data of flocked sheep;
[0030] The target recognition and detection module is used to input the acquired video data of the flocked sheep into the trained YOLOv9c target detection model and output the location and behavior status information of the sheep;
[0031] The target tracking module is used to continuously track all sheep according to the obtained sheep position and behavior status information combined with the improved ByteTrack algorithm; wherein the improved ByteTrack algorithm includes: introducing a time distance matching module before creating a new track, and introducing an ID delay allocation mechanism when creating a new track; the introduced time distance matching module is used to combine the long and short time lost track queues to re-match the targets that are lost due to the difficulty in predicting the position of the Kalman filter, including: calculating the Euclidean distance between the unmatched high-score detection frames and the long and short time lost tracks; calculating the duration of each lost track track relative to the current frame; and calculating the relationship coefficient between the track and the detection frame according to the Euclidean distance between the lost track and the detection frame and the duration of the track loss.
[0032] As a further technical solution, the training of the YOLOv9c target detection model includes:
[0033] Obtain an image dataset of flocked sheep, and label all the sheep in the selected image data to generate a dataset for training;
[0034] Use the labeled dataset to train the YOLOv9c target detection model and obtain the optimal model parameters.
[0035] According to one aspect of the present specification, there is provided an electronic device, comprising: at least one processor, at least one memory and a communication interface; wherein the processor, memory and communication interface communicate with each other; the memory stores program instructions executed by the processor, and the processor calls the program instructions to execute the described method.
[0036] According to one aspect of the present specification, a non-transitory computer-readable storage medium is provided, wherein the non-transitory computer-readable storage medium stores computer instructions, wherein the computer instructions enable the computer to execute the method described above.
[0037] Compared with the prior art, the present invention has the following beneficial effects:
[0038] The present invention combines the YOLOv9c model with the improved ByteTrack multi-target tracking algorithm, and realizes the automatic multi-target tracking and behavior recognition of sheep through video monitoring in the complex scene of actual flock-raising sheep. The present invention significantly alleviates the problems of difficulty in real-time tracking and behavior recognition of sheep due to long-term occlusion, fast movement, and similar appearance characteristics of sheep. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief introduction is given below to the drawings used in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0040] Figure 1 A schematic flow chart of a method for identifying behavior of flocked sheep based on a target detection and tracking algorithm provided in an embodiment of the present invention.
[0041] Figure 2 A schematic diagram of the YOLOv9c network model structure provided in an embodiment of the present invention.
[0042] Figure 3A schematic diagram of the effect of using the YOLOv9c network model to detect in various complex scenarios provided by an embodiment of the present invention;
[0043] Figure 4 This is a structural diagram of the improved ByteTrack tracking algorithm provided in an embodiment of the present invention, wherein Improvement 1 in the figure is a time distance matching module, and Improvement 2 is an ID delay allocation mechanism.
[0044] Figure 5 A schematic diagram of the structure of a time distance matching module provided in an embodiment of the present invention.
[0045] Figure 6 A schematic diagram of the effect of group-raising sheep behavior recognition and tracking based on YOLOv9c and improved ByteTrack algorithm provided in an embodiment of the present invention.
[0046] Figure 7 A schematic diagram of the structure of a group-raising sheep behavior recognition system based on a target detection and tracking algorithm provided in an embodiment of the present invention.
[0047] Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0048] The terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions, for example, a process, method, system, product or apparatus comprising a series of steps or units is not necessarily limited to the steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products or apparatuses.
[0049] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices. The flowcharts shown in the accompanying drawings are merely exemplary and do not necessarily include all the contents and operations / steps, nor do they necessarily have to be executed in the order described. For example, some operations / steps may be further decomposed, while some operations / steps may be combined or partially combined, so the actual execution order may change according to the actual situation.
[0050] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. In addition, the technical features in the various embodiments or single embodiments provided by the present invention are arbitrarily combined with each other to form a new technical solution. This combination is not restricted by the sequence of steps and / or the structural composition mode, but must be based on the ability of ordinary technicians in this field to achieve. When the combination of technical solutions is contradictory or cannot be achieved, it should be considered that this combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0051] An embodiment of the present invention provides a method for identifying the behavior of group-raised sheep based on a target detection and tracking algorithm, comprising: acquiring video data of group-raised sheep; inputting the acquired video data of the group-raised sheep into a trained YOLOv9c target detection model, and outputting the position and behavior status information of the sheep; and continuously tracking all the sheep according to the obtained sheep position and behavior status information in combination with an improved ByteTrack algorithm; wherein the improved ByteTrack algorithm comprises: introducing a time distance matching module before creating a new track, and introducing an ID delay allocation mechanism when creating a new track.
[0052] As a preferred embodiment, see Figure 1 The embodiment of the present invention provides a method for identifying the behavior of flocked sheep based on a target detection and tracking algorithm, comprising:
[0053] S1. Obtain an image dataset of flocked sheep, annotate all the sheep in the selected image data, and generate a true value dataset for training. This step specifically includes:
[0054] S11, selecting videos from different sheep pens and different time periods and using a Python script to capture frames from the selected videos at certain intervals;
[0055] S12. Use the Labelimg tool to annotate the image and mark the three states of the sheep, namely stand, eat and grovel.
[0056] The above steps are used to obtain the data set for training the YOLOv9c model.
[0057] S2. Use the labeled dataset to train the YOLOv9c target detection model and obtain the optimal model parameters.
[0058] The training parameters of the YOLOv9c target detection model include pre-trained model, iteration batch, number of iterations, initial learning rate, and weight decay. During training, the stochastic gradient descent method is used to update the weights.
[0059] S3: Input the video data of the flocked sheep into the trained YOLOv9c target detection model to obtain the location and behavior status information of the sheep. Specifically:
[0060] S31, YOLOv9c network structure please refer to Figure 2 The present invention divides YOLOv9c into five parts, namely, input, backbone, head, multi-level auxiliary information and auxiliary reversible branch. Among them, multi-level auxiliary information and auxiliary reversible branch are only used during training, and only input, backbone and head network are used during inference. Figure 2 In , Input means input, i.e. input image frame. Silence means no operation layer, which does not perform any operation by itself, and the output remains unchanged from the input. Conv means convolution layer, which extracts the spatial features of input data through convolution operation. Concat means concatenation layer, which concatenates multiple input data along the specified dimension to form a single output data. RepNCSPELAN4 means feature extraction-fusion module, whose core is Re-parameter + CSPNet + ELAN; Re-parameter is structural reparameterization, CSPNet is a cross-stage local network, and ELAN is an efficient layer aggregation network, which is used to improve the performance of the target detection model when processing targets of different sizes, while keeping the model lightweight and efficient. CBFuse means feature fusion layer, which is used for effective feature integration between feature maps of different depths. CBLinear means convolution block, which combines convolution layer (Conv), batch normalization layer (BatchNorm) and activation function (SiLU), so that CBLinear can enhance the information flow of the network through reversible connection when constructing the basic unit of the network. SPPELAN represents the fusion of efficient local aggregation network and spatial pyramid pooling layer. SPPELAN is a combination of spatial pyramid pooling (SPP) and efficient local aggregation network (ELAN), aiming to improve the effect of target detection by integrating the advantages of both. p3-p5 represents the output of detection boxes of different scales.
[0061] S32, target detection is to send the sheep video data to the trained YOLOv9c target detection network, YOLOv9c processes the video data frame by frame, selects objects that may be sheep and gives them corresponding behavior states, and then deletes most of the redundant target frames through the non-maximum suppression algorithm. The various information of the candidate frames obtained in the end, including frame coordinates, frame size, behavior category, etc., is passed to the improved ByteTrack target tracking algorithm.
[0062] S33, YOLOv9c can provide reliable target detection results in complex scenarios, see Figure 3 , even when the number of sheep exceeds the standard breeding environment, it can still provide relatively accurate behavior recognition and target detection effects.
[0063] S4, Improved ByteTrack multi-target tracking algorithm, see Figure 4 ,include:
[0064] S41. Design a queue of long and short lost trajectories, which can save not only short lost trajectories but also long lost trajectories. Short lost trajectories are trajectories that do not exceed the maximum lost tracking time specified by the original ByteTrack algorithm, and are mainly used for the first and second matching. Long lost trajectories are trajectories that exceed the maximum lost tracking time specified by the original ByteTrack algorithm. Short lost trajectories participate in the newly introduced time distance matching together with long lost trajectories, which makes it possible to successfully match again after the target is lost for a long time.
[0065] S42, introduce the time distance matching module, please refer to Figure 5 , re-matching the target that is lost due to long-term occlusion or too fast movement, which makes it difficult for the Kalman filter to predict the position. The specific steps are as follows:
[0066] A1. Calculate the Euclidean distance between the unmatched high-score detection frames and the long and short time loss trajectories. , Respectively represent The horizontal and vertical coordinates of the center point of the trajectory; use Respectively represent The horizontal and vertical coordinates of the center point of the detection box. Euclidean distance The formula is as follows:
[0067]
[0068] A2. Calculate the duration of each lost track relative to the current frame. Indicates The frame when the track is lost; Indicates the current frame. Time The calculation formula is as follows:
[0069] .
[0070] A3. Use the Euclidean distance between the lost track and the detection frame and the duration of track loss to calculate the relationship coefficient between the track and the detection frame. .use , It is used to adjust the proportion of time and distance in the relationship coefficient; Represents a very small number to avoid the denominator being 0. The calculation formula is as follows:
[0071] .
[0072] S43, introduce the delayed ID allocation mechanism. When the high confidence detection frame fails to match completely, it will be considered that a new sheep target has appeared, and the target will not be allocated immediately. The specific steps are as follows:
[0073] A1. When the current frame is the first frame, a new ID and a new track are assigned and the new track is marked as an activated track;
[0074] A2. When the current frame is not the first frame, no new ID is assigned, a new track is assigned and the new track is marked as an inactive track;
[0075] A3. In the stage of matching the inactive track with the detection frame, if the number of consecutive matches of the new track N is less than 3, the new track is discarded;
[0076] A4. In the stage of matching the inactivated track with the detection frame, when the new track is matched for N=3 times in a row, a new ID is assigned to the new track and the track is marked as an activated track.
[0077] S5. Continuously track all sheep based on the obtained sheep location information, including:
[0078] S51, based on the video data frame, the target detection algorithm detects the target, then uses the NMS algorithm to filter out redundant detection frames, and inputs the detection result into the tracking algorithm;
[0079] S52, the tracking algorithm divides the detection frame into two groups of high confidence and low confidence according to the confidence score of the detection frame, uses Kalman filtering to predict the target position of the next frame, performs the first IoU match between the predicted trajectory and the high-score detection frame, performs the second IoU match between the predicted trajectory and the low-score detection frame, performs IoU match between the inactivated trajectory and the high-score detection frame, and performs time distance match between the lost tracking trajectory and the high-score detection frame;
[0080] S53, using the Hungarian algorithm to obtain the first three matching results, obtaining the last matching result according to the magnitude of the time-distance relationship coefficient, and updating all trajectory states according to the matching results.
[0081] S54, Kalman filter update, output tracking results, repeat step A1 until the video ends.
[0082] The combination of YOLOv9c and the improved ByteTrack proposed in this invention can effectively perform behavior recognition and multi-target tracking on flocked sheep. Figure 6 In the figure, stand means standing and grovel means lying down. YOLOv9c can accurately identify the different behaviors of different sheep; the improved ByteTrack multi-target tracking algorithm of the present invention can accurately track the flocked sheep for a long time, significantly alleviating the problem of loss of tracking due to occlusion.
[0083] The implementation basis of each embodiment of the present invention is to implement programmed processing through a device with a processor function. Therefore, in engineering practice, the technical solutions and functions of each embodiment of the present invention are encapsulated into various modules. Based on this reality, on the basis of the above embodiments, an embodiment of the present invention provides a group-raising sheep behavior recognition system based on a target detection and tracking algorithm, which is used to execute the group-raising sheep behavior recognition method based on a target detection and tracking algorithm in the above method embodiment.
[0084] See also Figure 7 The system includes: an input module for acquiring video data of group-raised sheep; a target recognition and detection module for inputting the acquired video data of group-raised sheep into a trained YOLOv9c target detection model and outputting the location and behavior status information of the sheep; a target tracking module for continuously tracking all sheep based on the obtained location and behavior status information of the sheep in combination with an improved ByteTrack algorithm; wherein the improved ByteTrack algorithm includes: introducing a time distance matching module before creating a new track, and introducing an ID delay allocation mechanism when creating a new track.
[0085] The group-raising sheep behavior recognition system based on target detection and tracking algorithm provided by the embodiment of the present invention is aimed at real-time multi-target tracking and behavior recognition of group-raising sheep in complex scenes. Figure 7 Several modules in it have significantly alleviated the problems of real-time tracking and behavior recognition of sheep due to long-term occlusion, fast movement, and similar appearance characteristics of sheep.
[0086] It should be noted that the system embodiment provided by the present invention is used to implement the methods in the above method embodiment as well as the methods in other method embodiments provided by the present invention. The only difference is that the corresponding functional modules are set. The principle is basically the same as the principle of the above system embodiment provided by the present invention. As long as the technical personnel in this field refer to the specific technical solutions in other method embodiments on the basis of the above system embodiment, obtain the corresponding technical means and the technical solutions composed of these technical means by combining the technical features, and on the premise of ensuring the practicality of the technical solutions, improve the modules in the above system embodiment to obtain the corresponding system class embodiments, which are used to implement the methods in other method class embodiments. For example:
[0087] Based on the content of the above system embodiment, as a preferred embodiment, the group-raising sheep behavior recognition system based on the target detection and tracking algorithm provided in the embodiment of the present invention, the training of the YOLOv9c target detection model also includes:
[0088] Obtain an image dataset of flocked sheep, and label all the sheep in the selected image data to generate a dataset for training;
[0089] Use the labeled dataset to train the YOLOv9c target detection model and obtain the optimal model parameters.
[0090] Based on the contents of the above system embodiment, as a preferred embodiment, the group-raising sheep behavior recognition system based on the target detection and tracking algorithm provided in the embodiment of the present invention, the improved ByteTrack algorithm also includes:
[0091] Design a long and short lost trajectory queue to save short lost trajectories and long lost trajectories;
[0092] The time distance matching module is introduced to combine the long and short time lost trajectory queues to re-match the targets that are lost because the Kalman filter cannot predict the position.
[0093] A delayed ID allocation mechanism is introduced to delay the allocation of targets after a high-confidence detection box fails to fully match.
[0094] Based on the contents of the above system embodiment, as a preferred embodiment, the group-raising sheep behavior recognition system based on the target detection and tracking algorithm provided in the embodiment of the present invention, the target tracking module also includes:
[0095] Calculate the Euclidean distance between each pair of unmatched high-score detection frames and long and short-time loss trajectories;
[0096] Calculate the duration of each lost tracking trajectory relative to the current frame;
[0097] According to the Euclidean distance between the lost trajectory and the detection frame, combined with the duration of trajectory loss, the relationship coefficient between the trajectory and the detection frame is calculated.
[0098] Based on the contents of the above system embodiment, as a preferred embodiment, the group-raising sheep behavior recognition system based on the target detection and tracking algorithm provided in the embodiment of the present invention, the target tracking module also includes:
[0099] When the current frame is the first frame, a new ID and a new track are assigned and the new track is marked as an activated track;
[0100] When the current frame is not the first frame, no new ID is assigned, a new track is assigned and the new track is marked as an inactive track;
[0101] In the stage of matching the inactive track with the detection frame, if the number of consecutive matches of the new track is less than the preset number, the new track is discarded;
[0102] In the stage of matching the inactivated track with the detection frame, when the number of consecutive matches of the new track meets the preset number, a new ID is assigned to the new track and the track is marked as an activated track.
[0103] Based on the contents of the above system embodiment, as a preferred embodiment, the group-raising sheep behavior recognition system based on the target detection and tracking algorithm provided in the embodiment of the present invention, the target tracking module also includes:
[0104] Use the non-maximum suppression algorithm to filter out redundant detection boxes, and input the deleted detection results into the improved ByteTrack algorithm;
[0105] The improved ByteTrack algorithm divides the detection frames into two groups: high confidence and low confidence according to the detection frame confidence score. The Kalman filter is used to predict the target position of the next frame. The predicted trajectory is matched with the high-score detection frame for the first IoU, the predicted trajectory is matched with the low-score detection frame for the second IoU, the inactivated trajectory is matched with the high-score detection frame for IoU, and the lost trajectory is matched with the high-score detection frame for time distance.
[0106] Use the Hungarian algorithm to get the first three matching results, get the last matching result according to the time-distance relationship coefficient, and update all trajectory states according to the matching results;
[0107] The Kalman filter is updated and the tracking result is output.
[0108] The method of the embodiment of the present invention is implemented by relying on electronic devices, so it is necessary to introduce the relevant electronic devices. Based on this purpose, the embodiment of the present invention provides an electronic device, such as Figure 8As shown, the electronic device includes: at least one processor, a communication interface, at least one memory, and a communication bus, wherein at least one processor, the communication interface, and at least one memory communicate with each other through the communication bus. At least one processor calls the logic instructions in at least one memory to execute all or part of the steps of the method provided by the aforementioned various method embodiments.
[0109] In addition, when the logic instructions in the above-mentioned at least one memory are implemented in the form of a software functional unit and sold or used as an independent product, they are stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or partly in other words, the part that contributes to the prior art or part of the technical solution is embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for enabling a computer device (a personal computer, a server, or a network device) to perform all or part of the steps of the method described in each method embodiment of the present invention. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk, and various media for storing program codes.
[0110] The system embodiments described above are merely illustrative, wherein the units described as separate components are or are not physically separated, and the components shown as units are or are not physical units, located in one place, or distributed on multiple network units. Some or all of the modules are selected according to actual conditions to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement without creative effort.
[0111] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0112] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0113] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0114] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0115] In summary, the present invention first improves the ByteTrack tracking algorithm, introduces a time distance matching module before creating a new track, introduces an ID delay allocation mechanism when creating a new track after the high-score frame fails to fully match; collects and produces a target detection data set, and divides the sheep behavior into three states: standing (stand), eating (eat), and lying (grovel); uses the YOLOv9c target detection algorithm to detect the sheep position coordinates and behavior in the video image; the improved ByteTrack algorithm processes the sheep coordinates and behavior state information in the video frame detected by the YOLOv9c algorithm, and tracks multiple sheep at the same time. The present invention can be applied to the management of group-raised sheep farms, provides an effective technical means for real-time monitoring of sheep behavior, and largely alleviates the problem that other tracking algorithms are difficult to track continuously for a long time.
[0116] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the technical solutions of the embodiments of the present invention.
Claims
1. A method for identifying sheep behavior in groups based on target detection and tracking algorithm, characterized in that: include: Obtain video data of flocked sheep; The acquired video data of the flocked sheep is input into the trained YOLOv9c target detection model to output the location and behavior status information of the sheep; Based on the obtained information on sheep location and behavior status, combined with the improved ByteTrack algorithm, all sheep are continuously tracked; The improved ByteTrack algorithm includes: introducing a time distance matching module before creating a new track, and introducing an ID delay allocation mechanism when creating a new track; the introduction of the time distance matching module is used to combine the long and short time lost track queues to re-match the targets that are lost because the Kalman filter is difficult to predict the position, including: calculating the Euclidean distance between the unmatched high-score detection frames and the long and short time lost tracks; calculating the duration of each lost track track relative to the current frame; calculating the relationship coefficient between the track and the detection frame based on the Euclidean distance between the lost track and the detection frame and the duration of the track loss; The method continuously tracks all the sheep according to the obtained sheep position and behavior state information in combination with the improved ByteTrack algorithm, including: using a non-maximum suppression algorithm to screen out redundant detection frames, and inputting the deleted detection results into the improved ByteTrack algorithm; the improved ByteTrack algorithm divides the detection frames into two groups of high confidence and low confidence according to the detection frame confidence scores, uses Kalman filtering to predict the target position of the next frame, performs the first IoU matching of the predicted trajectory with the high-score detection frame, performs the second IoU matching of the predicted trajectory with the low-score detection frame, performs IoU matching of the unactivated trajectory with the high-score detection frame, and performs time distance matching of the lost tracking trajectory with the high-score detection frame; uses the Hungarian algorithm to obtain the first three matching results, obtains the last matching result according to the time distance relationship coefficient, and updates all trajectory states according to the matching results; updates the Kalman filter and outputs the tracking results.
2. The method for identifying sheep behavior in groups based on target detection and tracking algorithm according to claim 1 is characterized in that: The training of the YOLOv9c target detection model includes: Obtain an image dataset of flocked sheep, and label all the sheep in the selected image data to generate a dataset for training; Use the labeled dataset to train the YOLOv9c target detection model and obtain the optimal model parameters.
3. The method for identifying sheep behavior in groups based on target detection and tracking algorithm according to claim 1, characterized in that: The improved ByteTrack algorithm also includes: Design a long and short lost trajectory queue to save short lost trajectories and long lost trajectories; A delayed ID allocation mechanism is introduced to delay the allocation of targets after a high-confidence detection box fails to fully match.
4. The method for identifying behavior of flocked sheep based on target detection and tracking algorithm according to claim 3 is characterized in that: Introduce a delayed ID allocation mechanism to delay the allocation of targets after a high-confidence detection box fails to fully match, including: When the current frame is the first frame, a new ID and a new track are assigned and the new track is marked as an activated track; When the current frame is not the first frame, no new ID is assigned, a new track is assigned and the new track is marked as an inactive track; In the stage of matching the inactive track with the detection frame, if the number of consecutive matches of the new track is less than the preset number, the new track is discarded; In the stage of matching the inactivated track with the detection frame, when the number of consecutive matches of the new track meets the preset number, a new ID is assigned to the new track and the track is marked as an activated track.
5. A group-raising sheep behavior recognition system based on target detection and tracking algorithm, characterized in that: include: An input module for acquiring video data of flocked sheep; The target recognition and detection module is used to input the acquired video data of the flocked sheep into the trained YOLOv9c target detection model and output the location and behavior status information of the sheep; The target tracking module is used to continuously track all the sheep according to the obtained sheep position and behavior status information combined with the improved ByteTrack algorithm; wherein the improved ByteTrack algorithm includes: introducing a time distance matching module before creating a new track, and introducing an ID delay allocation mechanism when creating a new track, the introduced time distance matching module is used to combine the long and short time lost track queues, and re-match the targets that are lost because the Kalman filter is difficult to predict the position, including: calculating the Euclidean distance between the unmatched high-score detection frames and the long and short time lost tracks; calculating the duration of each lost track track relative to the current frame; calculating the relationship coefficient between the track and the detection frame according to the Euclidean distance between the lost track and the detection frame, combined with the track loss duration; The method continuously tracks all the sheep according to the obtained sheep position and behavior state information in combination with the improved ByteTrack algorithm, including: using a non-maximum suppression algorithm to screen out redundant detection frames, and inputting the deleted detection results into the improved ByteTrack algorithm; the improved ByteTrack algorithm divides the detection frames into two groups of high confidence and low confidence according to the detection frame confidence scores, uses Kalman filtering to predict the target position of the next frame, performs the first IoU matching of the predicted trajectory with the high-score detection frame, performs the second IoU matching of the predicted trajectory with the low-score detection frame, performs IoU matching of the unactivated trajectory with the high-score detection frame, and performs time distance matching of the lost tracking trajectory with the high-score detection frame; uses the Hungarian algorithm to obtain the first three matching results, obtains the last matching result according to the time distance relationship coefficient, and updates all trajectory states according to the matching results; updates the Kalman filter and outputs the tracking results.
6. The group-raising sheep behavior recognition system based on target detection and tracking algorithm according to claim 5 is characterized in that: The training of the YOLOv9c target detection model includes: Obtain an image dataset of flocked sheep, and label all the sheep in the selected image data to generate a dataset for training; Use the labeled dataset to train the YOLOv9c target detection model and obtain the optimal model parameters.
7. An electronic device, characterized in that: include: At least one processor, at least one memory and a communication interface; wherein the processor, memory and communication interface communicate with each other; The memory stores program instructions executed by the processor, and the processor calls the program instructions to execute the method according to any one of claims 1 to 4.
8. A non-transitory computer readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, which cause the computer to execute the method of any one of claims 1 to 4.
Citation Information
Patent Citations
Live pig multi-target tracking and behavior recognition method, computer equipment and storage medium
CN115830078A
Multi-target tracking and behavior statistics method for health-preserving pigs in group
CN115830490A