Real-time abnormal movement detection method for pigs based on improved FairMOT

By improving the FairMOT algorithm and using the improved YOLOv5s detector and Triplet Loss function, the problems of low tracking accuracy and frequent ID switch in pig farm environment are solved, real-time abnormal detection of pig exercise volume is realized, and tracking accuracy and real-time performance are improved.

CN117218718BActive Publication Date: 2025-08-19SOUTH CHINA AGRICULTURAL UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311025461.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-15
Publication Date
2025-08-19
Estimated Expiration
2043-08-15

AI Technical Summary

Technical Problem

The existing multi-objective tracking technology has problems such as low tracking accuracy and frequent ID switches in pig farm environments, and the real-time performance is insufficient, making it difficult to meet the needs of monitoring pig exercise volume.

Method used

The improved FairMOT algorithm is adopted, and the CenterNet detector is replaced with the improved YOLOv5s detector, and the Triplet Loss function is used on the re-identification branch, combining the global enhancement module GEM of the self-attention mechanism, optimize the detection and re-identification process, and improve tracking accuracy and real-timeness.

Benefits of technology

It effectively improves the accuracy and real-timeness of pig video tracking, reduces the ID switch frequency, and realizes accurate abnormal detection of pig exercise volume.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117218718B_ABST
    Figure CN117218718B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for detecting abnormalities in the real-time movement of pigs based on an improved FairMOT, comprising the following steps: S1, obtaining an initial video of the pigs, cropping the video, and labeling the pigs in the video using DarkLabel software to obtain a MOT format data set of the pigs, and dividing the data into a training set, a validation set, and a test set; S2, inputting the training set and the validation set into an improved FairMOT algorithm model for training and validation, and ultimately obtaining an optimal algorithm model; S3, using the optimal algorithm model to perform real-time multi-target tracking of the pigs in the test set, calculating the tracking trajectory of each pig to obtain the pig's movement volume, setting a pig's movement volume threshold, and issuing a warning when the pig's movement volume exceeds the threshold. The present invention solves the problems of low pig video tracking accuracy and frequent ID switching caused by pig farm environmental interference and target overlap, and effectively realizes abnormal detection of the real-time movement volume of pigs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of multi-target tracking in videos, and in particular to a method for detecting abnormalities in the real-time movement of pigs based on an improved FairMOT. Background Art

[0002] In pig farming, accurate and real-time monitoring of pig activity is crucial for assessing pig health and preventing disease. Traditional manual monitoring methods are labor-intensive and time-consuming, and are prone to errors. Therefore, developing an automated, efficient, and accurate method for monitoring pig activity is crucial.

[0003] Deep learning technology has been widely applied in image processing, object detection, and multi-object tracking. Multi-object tracking can be used to monitor pig activity. Current state-of-the-art multi-object tracking methods are generally categorized into two main categories: two-stage multi-object tracking and single-stage multi-object tracking. Two-stage multi-object tracking uses two separate models: a detection model first locates the bounding boxes of objects in the image, then an association model extracts re-identification features for each bounding box and associates the bounding box with an existing tracking result based on a specific metric defined by these features. Single-stage multi-object tracking simultaneously performs object detection and re-identification feature extraction. Its core concept is to perform object detection and identity embedding simultaneously within a single network, reducing inference time by sharing most computation. Compared to two-stage multi-object tracking algorithms, single-stage multi-object tracking significantly saves computation time and achieves higher real-time performance. Currently, most multi-object tracking technologies used for pig tracking are two-stage, which suffers from limited real-time performance. Furthermore, the homogeneous background of pig farms and the limited differentiation of individual pig features result in low tracking accuracy and frequent ID switching. Summary of the Invention

[0004] The purpose of the present invention is to overcome the shortcomings and deficiencies of the existing technology and propose a real-time pig motion anomaly detection method based on the improved FairMOT, which can effectively solve the problems of low pig video tracking accuracy and frequent ID switching caused by pig farm environmental interference and target overlap. At the same time, the use of a single-stage improved FairMOT algorithm effectively improves the real-time and accuracy of tracking.

[0005] To achieve the above objectives, the present invention provides a technical solution: a method for detecting abnormal pig movement in real time based on an improved FairMOT, comprising the following steps:

[0006] S1. Obtain an initial video of pigs, crop the video, and use DarkLabel software to label the pigs in the video to obtain a MOT format dataset of the pigs. The dataset is then divided into a training set, a validation set, and a test set.

[0007] S2. Input the training set and validation set into the improved FairMOT algorithm model for training and validation. The improvement to the FairMOT algorithm model is to replace the CenterNet detector in the detection branch of the FairMOT algorithm model with an improved YOLOv5s detector to improve the tracking accuracy of the algorithm, and replace the original cross entropy loss function with the Triplet Loss function in the re-identification branch to reduce the ID switch of the algorithm. The improvement to the YOLOv5s detector is to add a global enhancement module (GEM) based on the self-attention mechanism (MHSA) to the backbone network of the YOLOv5s detector. After parameter training and validation, an optimal algorithm model is finally obtained.

[0008] S3. Use the optimal algorithm model to perform real-time multi-target tracking of the pigs in the test set, calculate the tracking trajectory of each pig to obtain the pig's movement volume, set the pig's movement volume threshold, and issue a warning when the pig's movement volume exceeds the threshold, thereby realizing the abnormal detection of the pig's real-time movement volume.

[0009] Furthermore, the step S1 includes the following steps:

[0010] S101, the initial video of the pigs is collected from the pig farm monitoring;

[0011] S102, using DarkLabel, a dataset formatting software, to label the pig objects in each frame of the video, and save the labels in the MOT video data labeling format to obtain an MOT format dataset of the pigs;

[0012] S103 , dividing the data set into a training set for training, a validation set for verification during training, and a test set for testing after training.

[0013] Furthermore, in step S2, the improved FairMOT algorithm model includes: a backbone network DLA-34, a detection branch, and a re-identification branch;

[0014] The backbone network DLA-34 uses ResNet-34 as the backbone and applies an enhanced version of deep layer aggregation DLA to fuse multi-layer features; the convolutional layers in all upsampling modules are replaced by deformable convolutions, allowing them to dynamically adjust the receptive field according to the target scale and pose, helping to alleviate alignment issues;

[0015] In the detection branch, the CenterNet detector is replaced with an improved YOLOv5s detector, which improves the tracking accuracy of the model algorithm. Specifically, the backbone network of the YOLOv5s detector is improved by adding a global enhancement module (GEM) based on the self-attention mechanism (MHSA) to the backbone network, taking into account self-attention optimization and high-frequency information supplementation.

[0016] MHSA is a multi-head attention mechanism, which is used to solve the problem that the feature extraction module of convolutional neural networks is limited by the size of the receptive field and has a weak ability to extract the overall information and contextual information of the image. It is introduced into the backbone network to obtain long-range feature dependencies and model global information. In terms of self-attention calculation, MHSA first uses 1x1 convolution to flatten the input image into Q, K, and V vectors respectively, and then calculates the self-attention and obtains the weight map. In addition, the relative position code R is added when calculating the self-attention. h and R w , so that MHSA can effectively obtain the position-aware encoding between features, so that the relative position relationship between data can be effectively utilized in modeling;

[0017] The global enhancement module GEM is used to solve the problem that the self-attention module has weak ability to extract high-frequency information. It can be divided into a high-frequency information extraction module LEM-MLP, a global self-attention module MHSA and a spatial-channel bi-dimensional attention module BiMLP; among them, MHSA is used for self-attention extraction, while LEM-MLP is used to supplement the high-frequency information for the self-attention module to make up for the defects of the self-attention mechanism and improve the completeness of the feature information; in the design of local information supplementation, a high-frequency information extraction module LEM-MLP composed of a local enhancement module LEM and a multi-layer perceptron MLP is added before MHSA to pre-aggregate local information and extract target detail information for MHSA; in addition, in order to achieve the effect of high-frequency information supplementation and reduce redundant feature extraction, GEM divides the feature map channels of LEM and MHSA according to 1:3, and completes the supplement through separate extraction and Concat operations; BiMLP is used to perform concat on the information after concat in the last part of GEM. In order to eliminate channel interaction and nonlinear interaction, BiMLP uses two branches to filter and interact with the global information and local information of the combined feature map respectively: first, the channel information of the input feature map is modeled through a structure similar to the SENet channel attention. After obtaining the channel modeling information, the YOLOv5s detector can filter out important global and local feature information from the feature map after Concat. Subsequently, given that the feature map after Concat has both global feature information and local feature information, a spatial modeling branch is added on the basis of MLP. The spatial modeling branch consists of convolution operations and activation operations. Its function is to extract the spatial relationship between the global feature map and the local feature map, and based on the modeled spatial attention, the local information is better supplemented to the global information. Based on the above structure, BiMLP performs channel modeling and spatial modeling on the feature map after Concat, and effectively fuses the global information feature map and the local information feature map based on the modeling information, thereby obtaining more refined features;

[0018] In the backbone network of the YOLOv5s detector, GEM is inserted into the deep feature maps to improve network efficiency. Since the YOLOv5s detector needs to use the output feature maps of the last three C3 modules for feature fusion and target regression, GEM is added to the three output layers of the backbone network to avoid performance bottlenecks caused by global information loss in shallow feature maps. GEM is added after the two convolution branches of the C3 module to enhance global information. This new module with GEM insertion is named C3GEM. C3GEM avoids the performance burden caused by stacking self-attention by adding GEM as an enhancement module to the end of the module.

[0019] In the re-identification branch, the Triplet Loss function is used to replace the original cross entropy loss function; the goal of the Triplet Loss function is to minimize the distance between the feature vectors of the same target and maximize the distance between the positive sample and other different targets; during the training process, the Triplet Loss function selects a positive sample and a negative sample according to the feature vector of each target and calculates the distance between them. The Triplet Loss function is used to learn the similarities and differences between target features; in view of the large changes in the appearance and posture of pigs, the Triplet Loss function is used to better distinguish the similarities and differences between the same pig and different pigs, thereby reducing the ID switch of the FairMOT algorithm model; the Triplet Loss function L triplet It is expressed as follows:

[0020]

[0021] Where, f a is the feature vector of the anchor point, f p is the feature vector of the positive sample, f n is the feature vector of negative samples, and m is a constant.

[0022] Furthermore, in step S3, the optimal algorithm model obtained in step S2 is used to perform real-time multi-target tracking on the pigs in the test set. Based on the tracking results of the pigs, the temporal motion trajectory of each pig is calculated. Based on the length of the pig's motion trajectory, the amount of movement of the pig in the video is calculated. The trajectory length L is expressed as:

[0023]

[0024] Where n is the number of trajectory points, p i is the coordinate of the i-th trajectory point, p i+1 is the coordinate of the i+1th trajectory point;

[0025] Based on the collected pig exercise data, the average exercise volume and standard deviation of the pigs are calculated, and the abnormal exercise volume threshold of the pigs is determined according to statistical methods; the 3σ principle is used to define the exercise volume that exceeds the average exercise volume plus 3 times the standard deviation as the abnormal exercise volume threshold, and a warning is issued when the pig exercise volume in the video exceeds the threshold.

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

[0027] 1. The present invention is based on the improvement of the FairMOT algorithm (a single-stage multi-target tracking algorithm), which saves a lot of computing time, improves the operating efficiency and makes the model more real-time.

[0028] 2. The present invention uses a global enhancement module GEM based on the self-attention mechanism MHSA and applies it to the backbone network of the YOLOv5s detector, so that the YOLOv5s detector can effectively suppress background interference, thereby improving the detection accuracy of the detector.

[0029] 3. Based on FairMOT, this paper improves the detection branch and uses the improved YOLOv5s detector to replace the CenterNet detector of the original model, thereby improving the tracking accuracy of the model.

[0030] 4. Based on FairMOT, the present invention improves the re-identification branch and uses the Triplet Loss function to replace the cross entropy loss function of the original model to better distinguish the similarities and differences between the same pig and different pigs, thereby reducing the ID switch of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 This is the structural diagram of the improved FairMOT algorithm model. In the figure, DLA-34 is the backbone network, down sample is downsampling, up sample is upsampling, and keep resolution is keep resolution; Backbone is the backbone network, Neck is the feature pyramid, and Head is the target detection head in the detection branch; Re-ID Embeddings is re-identification embedding, and extract features is extracted features.

[0032] Figure 2 To improve the structure of the YOLOv5s detector, in the figure, Backbone is the backbone network, CBS block is the basic convolution module, C3 block is the residual convolution module, C3GEM block is the residual module after adding multi-head attention, SPPF block is the multi-scale enhancement module, Concat block is the fusion operation, Conv block is the convolution module, Neck is the feature pyramid, UpSample is upsampling, Head is the target detection head, and prediction is the prediction end.

[0033] Figure 3 Schematic diagram of the residual module C3GEM after adding multi-head self-attention to the backbone network of the YOLOv5s detector. The Input is the input end, the CBS block is the basic convolution module, the BottleNeck block is the bottleneck layer, the Concat block is the fusion operation, and the GEM block is the global enhancement module.

[0034] Figure 4Schematic diagram of the improved global enhancement module GEM used to improve the feature extraction module of the YOLOv5s detector, where Input is the input end, the CBS block is the basic convolution module, the LEM block is the local enhancement module, the MLP block is the multi-layer perceptron module, the AvgPool block is the average pooling module, the MHSA block is the multi-head self-attention mechanism module, the BiMLP block is the spatial-channel two-dimensional attention module, the BN block is the batch normalization processing module, the ReLU block is the nonlinear activation function, the Conv block is the convolution module, the GroupConv block is the group convolution module, and the Sigmoid block is the activation function.

[0035] Figure 5 This is the structural diagram of the multi-head self-attention mechanism MHSA, where Input is the input end, 1x1Conv block is the convolution module, Q(query) is the query vector, K(key) is the key vector, V(value) is the value vector, Rh and Rw are relative position codes, P(position) is the position vector, softmax block is the activation function, and Output is the output end. DETAILED DESCRIPTION

[0036] The present invention will be further described below with reference to specific embodiments.

[0037] like Figures 1 to 5 As shown, this embodiment discloses a method for detecting abnormal pig movement in real time based on an improved FairMOT, comprising the following steps:

[0038] S1. Obtain the initial video of the pigs, crop the video, and use DarkLabel software to label the pigs in the video to obtain the MOT format dataset of the pigs. The dataset is divided into a training set, a validation set, and a test set. The details are as follows:

[0039] S101, the initial video of the pigs is collected from the pig farm monitoring;

[0040] S102, using DarkLabel, a dataset formatting software, to label the pig objects in each frame of the video, and save the labels in the MOT video data labeling format to obtain an MOT format dataset of the pigs;

[0041] S103 , dividing the data set into a training set for training, a validation set for verification during training, and a test set for testing after training.

[0042] S2. Input the training set and validation set into the improved FairMOT algorithm model for training and validation. The improvement to the FairMOT algorithm model is to replace the CenterNet detector in the detection branch of the FairMOT algorithm model with the improved YOLOv5s detector to improve the tracking accuracy of the algorithm, and replace the original cross entropy loss function with the Triplet Loss function in the re-identification branch to reduce the ID switch of the algorithm. The improvement to the YOLOv5s detector is to add a global enhancement module GEM based on the self-attention mechanism MHSA to the backbone network of the YOLOv5s detector. After parameter training and validation, an optimal algorithm model is finally obtained. The details are as follows:

[0043] The improved FairMOT algorithm model includes: a backbone network DLA-34, a detection branch and a re-identification branch;

[0044] The backbone network DLA-34 uses ResNet-34 as the backbone and applies an enhanced version of deep layer aggregation DLA to fuse multi-layer features; the convolutional layers in all upsampling modules are replaced by deformable convolutions, allowing them to dynamically adjust the receptive field according to the target scale and pose, helping to alleviate alignment issues;

[0045] In the detection branch, the CenterNet detector is replaced with an improved YOLOv5s detector, which improves the tracking accuracy of the model algorithm. Specifically, the backbone network of the YOLOv5s detector is improved by adding a global enhancement module (GEM) based on the self-attention mechanism (MHSA) to the backbone network, taking into account self-attention optimization and high-frequency information supplementation.

[0046] MHSA is a multi-head attention mechanism, which is used to solve the problem that the feature extraction module of convolutional neural networks is limited by the size of the receptive field and has a weak ability to extract the overall information and contextual information of the image. It is introduced into the backbone network to obtain long-range feature dependencies and model global information. In terms of self-attention calculation, MHSA first uses 1x1 convolution to flatten the input image into Q, K, and V vectors respectively, and then calculates the self-attention and obtains the weight map. In addition, the relative position code R is added when calculating the self-attention. h and R w , so that MHSA can effectively obtain the position-aware encoding between features, so that the relative position relationship between data can be effectively utilized in modeling;

[0047] The global enhancement module GEM is used to solve the problem that the self-attention module has weak ability to extract high-frequency information. It can be divided into a high-frequency information extraction module LEM-MLP, a global self-attention module MHSA and a spatial-channel bi-dimensional attention module BiMLP; among them, MHSA is used for self-attention extraction, while LEM-MLP is used to supplement the high-frequency information for the self-attention module to make up for the defects of the self-attention mechanism and improve the completeness of the feature information; in the design of local information supplementation, a high-frequency information extraction module LEM-MLP composed of a local enhancement module LEM and a multi-layer perceptron MLP is added before MHSA to pre-aggregate local information and extract target detail information for MHSA; in addition, in order to achieve the effect of high-frequency information supplementation and reduce redundant feature extraction, GEM divides the feature map channels of LEM and MHSA according to 1:3, and completes the supplement through separate extraction and Concat operations; BiMLP is used to perform concat on the information after concat in the last part of GEM. In order to eliminate channel interaction and nonlinear interaction, BiMLP uses two branches to filter and interact with the global information and local information of the combined feature map respectively: first, the channel information of the input feature map is modeled through a structure similar to the SENet channel attention. After obtaining the channel modeling information, the YOLOv5s detector can filter out important global and local feature information from the feature map after Concat. Subsequently, given that the feature map after Concat has both global feature information and local feature information, a spatial modeling branch is added on the basis of MLP. The spatial modeling branch consists of convolution operations and activation operations. Its function is to extract the spatial relationship between the global feature map and the local feature map, and based on the modeled spatial attention, the local information is better supplemented to the global information. Based on the above structure, BiMLP performs channel modeling and spatial modeling on the feature map after Concat, and effectively fuses the global information feature map and the local information feature map based on the modeling information, thereby obtaining more refined features;

[0048] In the backbone network of the YOLOv5s detector, GEM is inserted into the deep feature maps to improve network efficiency. Since the YOLOv5s detector needs to use the output feature maps of the last three C3 modules for feature fusion and target regression, GEM is added to the three output layers of the backbone network to avoid performance bottlenecks caused by global information loss in shallow feature maps. GEM is added after the two convolution branches of the C3 module to enhance global information. This new module with GEM insertion is named C3GEM. C3GEM avoids the performance burden caused by stacking self-attention by adding GEM as an enhancement module to the end of the module.

[0049] In the re-identification branch, the Triplet Loss function is used to replace the original cross entropy loss function; the goal of the Triplet Loss function is to minimize the distance between the feature vectors of the same target and maximize the distance between the positive sample and other different targets; during the training process, the Triplet Loss function selects a positive sample and a negative sample according to the feature vector of each target and calculates the distance between them. The Triplet Loss function is used to learn the similarities and differences between target features; in view of the large changes in the appearance and posture of pigs, the Triplet Loss function is used to better distinguish the similarities and differences between the same pig and different pigs, thereby reducing the ID switch of the FairMOT algorithm model; the Triplet Loss function L triplet It is expressed as follows:

[0050]

[0051] Where, f a is the feature vector of the anchor point, f p is the feature vector of the positive sample, f n is the feature vector of negative samples, and m is a constant.

[0052] S3. Use the optimal algorithm model to perform real-time multi-target tracking of the pigs in the test set, calculate the tracking trajectory of each pig to obtain the pig's movement volume; set the pig's movement volume threshold, and issue a warning when the pig's movement volume exceeds the threshold, thereby realizing the abnormal detection of the pig's real-time movement volume. The specific situation is as follows:

[0053] Use the optimal algorithm model obtained in step S2 to perform real-time multi-target tracking on the pigs in the test set; calculate the temporal motion trajectory of each pig based on the tracking results; calculate the amount of movement of the pig in the video based on the length of the pig's motion trajectory; the trajectory length is expressed as:

[0054]

[0055] Where n is the number of trajectory points, p i is the coordinate of the i-th trajectory point, p i+1 is the coordinate of the i+1th trajectory point;

[0056] Based on the collected pig exercise data, the statistical quantities such as the average exercise volume and standard deviation of the pigs are calculated, and the abnormal exercise volume threshold of the pigs is determined according to statistical methods; the 3σ principle is used to define the exercise volume exceeding the average exercise volume plus 3 times the standard deviation as the abnormal exercise volume threshold, and a warning is issued when the pig exercise volume in the video exceeds the threshold.

[0057] In summary, the present invention overcomes the problems of low tracking accuracy, frequent ID switches and low real-time performance of the original technology. Based on the FairMOT algorithm model, a real-time motion abnormality detection method for pigs is proposed, which is trained and detected on a pig video dataset. The CenterNet detector of the original FairMOT detection branch is replaced with an improved YOLOv5s detector, and the cross-entropy loss function of the re-identification branch is replaced with a Triplet Loss function to improve the tracking accuracy of the algorithm and reduce ID switches, thereby achieving more accurate identification and tracking of pigs in the video stream. The method has practical application value and is worthy of promotion.

[0058] The above-described embodiments are only preferred embodiments of the present invention and are not intended to limit the scope of implementation of the present invention. Therefore, any changes made based on the shape and principle of the present invention should be included in the scope of protection of the present invention.

Claims

1. A real-time abnormal motion detection method for pigs based on improved FairMOT, characterized by: The following steps are involved: S1. Obtain an initial video of pigs, crop the video, and use DarkLabel software to label the pigs in the video to obtain a MOT format dataset of the pigs. The dataset is then divided into a training set, a validation set, and a test set. S2. Input the training set and validation set into the improved FairMOT algorithm model for training and validation. The improvement to the FairMOT algorithm model is to replace the CenterNet detector in the detection branch of the FairMOT algorithm model with an improved YOLOv5s detector to improve the tracking accuracy of the algorithm, and replace the original cross entropy loss function with the Triplet Loss function in the re-identification branch to reduce the ID switch of the algorithm. The improvement to the YOLOv5s detector is to add a global enhancement module (GEM) based on the self-attention mechanism (MHSA) to the backbone network of the YOLOv5s detector. After parameter training and validation, an optimal algorithm model is finally obtained. S3. Use the optimal algorithm model to perform real-time multi-target tracking of the pigs in the test set, calculate the tracking trajectory of each pig to obtain the pig's movement volume, set the pig's movement volume threshold, and issue a warning when the pig's movement volume exceeds the threshold, thereby realizing the abnormal detection of the pig's real-time movement volume.

2. The method for detecting abnormal pig movement in real time based on the improved FairMOT according to claim 1, characterized in that: The step S1 comprises the following steps: S101, the initial video of the pigs is collected from the pig farm monitoring; S102, using DarkLabel, a dataset formatting software, to label the pig objects in each frame of the video, and save the labels in the MOT video data labeling format to obtain an MOT format dataset of the pigs; S103 , dividing the data set into a training set for training, a validation set for verification during training, and a test set for testing after training.

3. The method for detecting abnormal pig movement in real time based on improved FairMOT according to claim 2, characterized in that: In step S2, the improved FairMOT algorithm model includes: a backbone network DLA-34, a detection branch and a re-identification branch; The backbone network DLA-34 uses ResNet-34 as the backbone and applies an enhanced version of deep layer aggregation DLA to fuse multi-layer features; the convolutional layers in all upsampling modules are replaced by deformable convolutions so that they can dynamically adjust the receptive field according to the target scale and pose; In the detection branch, the CenterNet detector is replaced with an improved YOLOv5s detector. The backbone network of the YOLOv5s detector is improved, and a global enhancement module (GEM) based on the self-attention mechanism (MHSA) is added to the backbone network. MHSA is a multi-head attention mechanism, which is introduced into the backbone network to obtain long-range feature dependencies and model global information. In terms of self-attention calculation, MHSA first uses 1x1 convolution to flatten the input image into Q, K, and V vectors respectively, and then calculates the self-attention and obtains the weight map. In addition, relative position encoding R is added when calculating self-attention. h and R w , so that MHSA can effectively obtain the position-aware encoding between features; The global enhancement module GEM can be divided into a high-frequency information extraction module LEM-MLP, a global self-attention module MHSA and a spatial-channel bidimensional attention module BiMLP; among them, MHSA is used for self-attention extraction, while LEM-MLP is used to supplement the high-frequency information for the self-attention module; in the design of local information supplementation, a high-frequency information extraction module LEM-MLP composed of a local enhancement module LEM and a multi-layer perceptron MLP is added before MHSA, so as to pre-aggregate local information and extract target detail information for MHSA; GEM divides the feature map channels of LEM and MHSA according to 1:3, and completes the supplement through separate extraction and Concat operations; BiMLP is used to perform channel interaction and nonlinear interaction on the concat information in the last part of GEM, and BiMLP uses a dual-branch form to respectively perform channel interaction and nonlinear interaction on the combined features The global information and local information of the graph are filtered and interacted: First, the channel information of the input feature map is modeled through a structure similar to the SENet channel attention. After obtaining the channel modeling information, the YOLOv5s detector can filter out important global and local feature information from the Concat feature map. Subsequently, given that the Concat feature map has both global and local feature information, a spatial modeling branch is added on the basis of MLP. The spatial modeling branch consists of convolution operations and activation operations. Its function is to extract the spatial relationship between the global feature map and the local feature map, and based on the modeled spatial attention, the local information is better supplemented to the global information. Based on the above structure, BiMLP performs channel modeling and spatial modeling on the Concat feature map, and effectively fuses the global information feature map and the local information feature map based on the modeling information; In the backbone network of the YOLOv5s detector, GEM is inserted into the deep feature map to improve network efficiency. Since the YOLOv5s detector needs to use the output feature maps of the last three C3 modules for feature fusion and target regression, GEM is added to the three output layers of the backbone network. GEM is added after the two convolution branches of the C3 module to enhance global information. This new module with GEM insertion is named C3GEM. C3GEM is achieved by adding GEM as an enhancement module to the end of the module. In the re-identification branch, the Triplet Loss function is used to replace the original cross entropy loss function; the goal of the Triplet Loss function is to minimize the distance between the feature vectors of the same target and maximize the distance between the positive sample and other different targets; during the training process, the Triplet Loss function selects a positive sample and a negative sample according to the feature vector of each target and calculates the distance between them. The Triplet Loss function is used to learn the similarities and differences between target features; in view of the large changes in the appearance and posture of pigs, the Triplet Loss function is used to better distinguish the similarities and differences between the same pig and different pigs, thereby reducing the ID switch of the FairMOT algorithm model; the Triplet Loss function L triplet It is expressed as follows: Where, f a is the feature vector of the anchor point, f p is the feature vector of the positive sample, f n is the feature vector of negative samples, and m is a constant.

4. The method for detecting abnormal pig movement in real time based on improved FairMOT according to claim 3, characterized in that: In step S3, the optimal algorithm model obtained in step S2 is used to perform real-time multi-target tracking of the pigs in the test set. Based on the tracking results of the pigs, the temporal motion trajectory of each pig is calculated. Based on the length of the pig's motion trajectory, the amount of movement of the pig in the video is calculated. The trajectory length L is expressed as: Where n is the number of trajectory points, p i is the coordinate of the i-th trajectory point, p i+1 is the coordinate of the i+1th trajectory point; Based on the collected pig exercise data, the average exercise volume and standard deviation of the pigs are calculated, and the abnormal exercise volume threshold of the pigs is determined according to statistical methods; the 3σ principle is used to define the exercise volume that exceeds the average exercise volume plus 3 times the standard deviation as the abnormal exercise volume threshold, and a warning is issued when the pig exercise volume in the video exceeds the threshold.

Citation Information

Patent Citations

  • Vehicle tracking method based on CenterNet multi-target tracking algorithm

    CN113034545A

  • Small target tracking method based on anchor-frame-free detection network and feature refusion module

    CN116309704A