Animal real-time tracking and positioning method in multi-target scene and computer device
By using YOLOv11-EMA and SegFormer-Tiny models in the farm for real-time animal positioning, the problem of difficulty in precise positioning of animals in high-density breeding is solved, and more efficient feeding management and disease control are achieved.
Patent Information
- Application Number
- CN202510070042.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-02-25
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art is difficult to achieve precise positioning of animals in high-density breeding, resulting in low feeding efficiency and difficult to control disease transmission.
The YOLOv11-EMA object detection model and SegFormer-Tiny semantic segmentation model are adopted. Through real-time data acquisition and preprocessing, the object detection box is constructed and segmented, and a unique feature vector is assigned to each animal to achieve real-time tracking and positioning.
It improves the accuracy of real-time tracking and positioning of animals, reduces the dependence of manual observations, reduces the risk of equipment damage and disease transmission, and improves the economic benefits of breeding.
Smart Images

Figure CN119516446A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of real-time tracking and positioning of animals, and in particular to a real-time tracking and positioning method and a computer device for animals in a multi-target scene. Background Art
[0002] my country's breeding industry mainly relies on traditional artificial breeding methods. It is difficult to achieve accurate positioning of individuals in high-density breeding, and it is not easy to grasp the specific growth conditions of livestock, which affects economic benefits.
[0003] At present, the main method is to use manual observation or electronic ear tags combined with monitoring equipment installed on the farm for observation, such as a method and device for tracking and locating a free-range livestock group disclosed in application number 202311003560.8, which includes an electronic ear tag and a collar device. The livestock group includes a leading livestock group; the collar device is worn on the livestock in the leading livestock group; the electronic ear tag is worn on all livestock in the livestock group. First, the accurate position of the collar device is obtained through the positioning module, and secondly, the distance between all livestock in the livestock group and the collar device is obtained through active RFID. The location information and the distance information of all livestock are sent to the application server through the communication module, and the tracking and positioning information of the livestock group is obtained through analysis and processing, and pushed to the mobile phone application of the herder for display, thereby improving the tracking and positioning capabilities of the free-range livestock group.
[0004] However, the current scheme has the following drawbacks: manual observation is inefficient and prone to miscounts and omissions; the initial investment cost of electronic ear tags is relatively high, and they are easily lost or damaged during operation, making it difficult to detect sick livestock in time, leading to widespread spread of the disease. Summary of the invention
[0005] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a method and a computer device for real-time tracking and positioning of animals in a multi-target scene, thereby improving the accuracy of real-time tracking and positioning of animals.
[0006] The present invention adopts the following technical solutions to achieve the above-mentioned purpose. In a first aspect, the present invention provides a method for real-time tracking and positioning of animals in a multi-target scene, comprising: S1, collect real-time data; S2, preprocessing the collected data; S3. Build a YOLOv11-EMA target detection model, input the processed data into the YOLOv11-EMA target detection model, and obtain a target image containing a target detection frame; S4, input the target image containing the target detection frame into the SegFormer-Tiny model, and segment the target image in the target detection frame; S5. Assign a unique feature vector as an identification mark to each segmented target image. The feature vector matches the individual animal. In subsequent target detection, once a target matching the feature vector is detected, it is identified, tracked and counted.
[0007] Furthermore, step S3 specifically includes: Add the EMA module to the tail of Backbone and Neck of the YOLOv11 target detection model at the same time to obtain the YOLOv11-EMA target detection model; The processed data is grouped by features, and the channel dimension of the input feature map is divided into G groups, each group contains C / G channels, and the grouping method is as follows: , where X is the input feature map, X i , i=1,2,...,G-1, represents the i-th channel group; The grouped data is fed into the parallel sub-network. The EMA module processes the features through two parallel branches. The 1x1 convolution branch maps each set of features of X into space, preserving the local contextual relationship, as follows: , Indicates a 1x1 convolution operation on the input feature map X; The 3x3 convolution branch captures local and multi-scale features in the following way: , Indicates a 3x3 convolution operation on the input feature map X; Global average pooling is divided into global average pooling in two directions: horizontal and vertical, which capture global features in the horizontal and vertical directions respectively; , ; in, Indicates The first The eigenvalues at the positions, , Respectively represent the global average pooling results along the width and height directions, H represents the height of the feature map, and W represents the width of the feature map; The EMA module then aggregates the output features of the two parallel branches through a matrix dot product operation to capture the pairwise relationship at the pixel level and realize feature aggregation and interaction as follows: ; ; ; ; in, , as well as represents the intermediate variable, and It is the spatial attention map after adaptive average pooling and Softmax normalization. and is the transformation of the corresponding feature map, represents the matrix product of the feature map, weights is the final calculated weight map, b represents the batch size, and represents the number of samples in the current batch. is the number of feature groups, used to reduce computational complexity, Indicates combining batch and group. Represents the operation of reshaping the array. Finally, the EMA module applies the resulting weight map to the original tensor and reconstructs it into the original input shape.
[0008] Furthermore, the SegFormer-Tiny model contains a multi-layer perceptron decoder and a Transformer encoder; The decoder process steps are as follows: The multi-level features Fi are unified into channel dimensions through a multi-layer perceptron layer; Upsample multi-level features to 1 / 4 resolution and concatenate them together; Use multi-layer perceptron layers to fuse the concatenated features and predict the fused features as segmentation masks; The calculation formula of EMA module self-attention is: ; in They are query, key and value, is the dimension of each head, t represents the transpose operation, yes The transposed matrix of express Activation function.
[0009] Furthermore, the SegFormer-Tiny model uses model pruning and quantization operations to remove redundant parameters and connections in the network, reducing the size and computation of the SegFormer-Tiny model as follows: Set the weight matrix to , the weight matrix after pruning is ,but: ,in represents the pruning threshold; The floating-point weights and activations are compressed by quantization to reduce the storage and computation requirements of the SegFormer-Tiny model as follows: , Represents the quantized weight, round represents the rounding operation, S is the scaling factor, It is a floating point weight.
[0010] Furthermore, step S2 specifically includes: performing data preprocessing by using mosaic or mixup.
[0011] In a second aspect, the present invention provides a computer device, including a memory, wherein the memory stores program instructions, and when the program instructions are executed, the above-mentioned method for real-time tracking and positioning of animals in a multi-target scenario is executed.
[0012] The beneficial effects of the present invention are: The present invention first sends the processed original image to the YOLOv11-EMA target detection model to obtain a picture containing a target detection frame. Through the ROI multi-sensory attention method, the part containing only the target detection frame is sent to the self-improved SegFormer semantic segmentation model, and the target in the target detection frame is accurately instance-segmented. A unique feature vector is assigned to each segmented object as an identification mark, and the feature vector matches the individual animal. In the subsequent target detection, once a target that meets the feature vector is detected, it is identified, tracked and counted. When the target disappears from the field of view, the tracking is stopped, thereby realizing real-time tracking and positioning of the animal. The accuracy of real-time tracking and positioning of animals is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 This is a flow chart of a method for real-time tracking and positioning of animals in a multi-target scenario provided by an embodiment of the present invention; Figure 2 It is a schematic diagram of the YOLOv11 model structure provided by an embodiment of the present invention; Figure 3 It is a schematic diagram of the YOLOv11-EMA model structure provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0014] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0015] The present invention provides a method for real-time tracking and positioning of animals in a multi-target scene, such as Figure 1 As shown, including: S1, collect real-time data; Data is collected through real-time cameras, and users manually upload pictures or video data.
[0016] S2, preprocessing the collected data; Use mosaic or mixup for data preprocessing.
[0017] S3. Build a YOLOv11-EMA target detection model, input the processed data into the YOLOv11-EMA target detection model, and obtain a target image containing a target detection frame; like Figure 2 As shown in the figure, the structure of the YOLOv11 model can be mainly divided into Backbone network, Neck network and Head network, which respectively play the role of image features, fusing multi-scale feature maps, processing and decoding feature maps.
[0018] The main function of the Backbone network is to extract features and continuously reduce the feature map. The main structures in the Backbone include Conv module, C3K2 module, SPPF module and C2PSA module, which can enhance the model's ability to extract features.
[0019] As convolution continues, the neural network extracts more and more features, and the layers become deeper and deeper. In the shallow layers of the convolutional neural network, the features extracted by the network are relatively simple; as the network continues to deepen, the neural network will continue to fuse these features, upgrade the dimensions, and generate new features. The Neck structure realizes the fusion of shallow graphic features and deep semantic features.
[0020] The head layer is the Detect module, which is divided into two categories: positioning detection head and classification detection head. In the positioning detection head, two CBSs plus one 1*1 convolution are used to match the number of channels, while two DWConvs (Depth-wise Separable Convolutions) are added to the classification detection head. Depth-wise separable convolutions decompose the standard convolution operation into two smaller operations: depthwise convolution and pointwise convolution. The original two ordinary convolutions form two depth-wise separable convolutions.
[0021] The present invention improves the accuracy of the network by adding an attention mechanism on the framework of YOLOv11.
[0022] The EMA (Efficient Multi-Scale Attention) module is a novel and efficient multi-scale attention mechanism that aims to improve the feature representation effect in computer vision tasks. The EMA module achieves more efficient and effective feature representation by combining channel and spatial information, adopting a multi-scale parallel sub-network structure, and optimizing the coordinate attention mechanism, providing important technical support for improving the performance of computer vision tasks.
[0023] like Figure 3 As shown, the present invention adds the EMA module to the tail of the Backbone of YOLOv11, and obtains the YOLOv11-EMA target detection model. By introducing multi-layer attention, the model's perception of data flow is enhanced, and the detection accuracy is improved.
[0024] The processed data is grouped by features, and the channel dimension of the input feature map is divided into G groups, each group contains C / G channels, and the grouping method is as follows: , where X is the input feature map, X i , i=1,2,...,G-1, represents the i-th channel group; The grouped data is input into the parallel sub-network. The EMA module contains two parallel convolution branches, a 1x1 convolution branch and a 3x3 convolution branch. The 1x1 branch handles local cross-channel interactions, and the 3x3 branch captures spatial information. The EMA module encodes channel information along two spatial dimensions through two 1 global average pooling operations: The 1x1 convolution branch can map each set of features of X into a smaller space, preserving the local contextual relationship, as follows: , Represents the feature map after 1x1 convolution, Indicates a 1x1 convolution operation on the input feature map X; The 3x3 convolution branch captures local and multi-scale features in the following way: , Represents the feature map after 3x3 convolution, Indicates a 3x3 convolution operation on the input feature map X; Global average pooling is divided into horizontal and vertical direction Global average pooling in two directions captures global features in the horizontal and vertical directions respectively. Parallel convolution operations and global average pooling are designed to improve the model's feature extraction of images, and the two run in parallel.
[0025] , ; in, Indicates The first The eigenvalues at the positions, , Respectively represent the global average pooling results along the width and height directions, H represents the height of the feature map, and W represents the width of the feature map; The EMA module then aggregates the output features of the two parallel branches through a matrix dot product operation to capture the pairwise relationship at the pixel level and realize feature aggregation and interaction as follows: ; ; ; ; in, , as well as represents the intermediate variable, and It is the spatial attention map after adaptive average pooling and Softmax normalization. and is the transformation of the corresponding feature map, represents the matrix product of the feature map, weights is the final calculated weight map, b represents the batch size, and represents the number of samples in the current batch. is the number of feature groups, used to reduce computational complexity, Indicates combining batch and group. Represents the operation of adjusting the shape of the array. Finally, the EMA module applies the obtained weight map to the original tensor and reconstructs it into the original input shape to enhance or weaken the original input features.
[0026] Through the above mechanism, the EMA module effectively combines channel and spatial information, and through a multi-scale parallel sub-network structure and cross-space learning, it improves the model's ability to model long-distance dependencies, thereby improving the effect of feature representation.
[0027] S4, input the target image containing the target detection frame into the SegFormer-Tiny model, and segment the target image in the target detection frame; The present invention adopts the SegFormer-Tiny model, which is a Transformer framework for semantic segmentation. It achieves simple, efficient and powerful semantic segmentation by combining a lightweight multi-layer perceptron decoder. SegFormer-Tiny contains a novel hierarchical Transformer encoder that outputs multi-scale features. This encoder does not require position encoding, thus avoiding the performance degradation caused by the interpolation of position codes when the test resolution is different from the training resolution. The encoder goal of SegFormer-Tiny is to generate CNN-like multi-level features, which provide high-resolution coarse features and low-resolution fine-grained features, which can generally improve the performance of semantic segmentation. Efficient self-attention, the self-attention layer is the main computational bottleneck of the encoder. SegFormer-Tiny uses a sequence simplification process to reduce complexity by reducing the sequence length.
[0028] SegFormer-Tiny uses a lightweight decoder consisting only of multi-layer perceptron layers, avoiding complex and computationally intensive modules. The key to this decoder is to utilize the features produced by the Transformer encoder, which have a larger effective receptive field (ERF) than traditional CNNs.
[0029] The decoder process steps are as follows: Step 1: Multi-level features The channel dimensions are unified through the multi-layer perception machine layer as follows: This formula represents the linear operation of the feature The channel dimension changes from C i Mapping to a uniform number of channels C , the purpose is to align the channels.
[0030] Step 2: Upsample the multi-level features to 1 / 4 resolution and concatenate them together; This formula indicates that the spatial resolution of the channel-aligned features is increased by upsampling. , ready to be spliced with features from other branches. The role of this step is spatial alignment to ensure that all features can be effectively fused in the spatial dimension.
[0031] Step 3: Use the multi-layer perceptron to fuse and splice features and predict the fused features as segmentation masks; This formula indicates that all upsampled features are concatenated in the channel dimension through Concat to form a fused feature. F , the fused feature F is then passed through a Linear layer to reduce the number of channels to Nclass and generate a segmentation mask M.
[0032] in It is a splicing operation. is the number of categories, Represents an upsampling operation, which is used to increase the resolution of the feature map to a higher spatial size.
[0033] The calculation formula of self-attention is: ; in They are query, key and value, is the dimension of each head, t represents the transpose operation, yes The transposed matrix of express Activation function; EMA generates multi-scale feature representations through 1x1 and 3x3 convolutions. These features are essentially equivalent to different identification forms of Q, K, and V. Global average pooling extracts context information, which is equivalent to providing global encoding for Q and K. Parallel branch convolution generates local features V and provides weighted feature values. EMA's attention mechanism is a simplification and adaptation of the self-attention mechanism, which is suitable for tasks with limited computer resources.
[0034] The sequence simplification process uses the reduction ratio To reduce the sequence length: in is a simplified sequence, and They are operations for adjusting the shape of arrays and linear layer operations; The main purpose of sequence simplification is to optimize computational efficiency by reducing the dimensionality of the input information and indirectly reducing the computational complexity of the encoder.
[0035] The SegFormer-Tiny model achieves simple, efficient, and powerful semantic segmentation through its hierarchical Transformer encoder and lightweight All-MLP decoder. It avoids the need for positional encoding, exploits the long-range dependencies of the Transformer, and achieves significant performance and efficiency improvements over traditional CNN methods through a lightweight decoder design.
[0036] The SegFormer-Tiny model uses model pruning and quantization.
[0037] Pruning removes redundant parameters and connections in the network to reduce the size and computation of the model. Train a complete model to identify and remove parameters that have little impact on the model output. Fine-tune the pruned model to restore performance.
[0038] Set the weight matrix to , the weight matrix after pruning is ,but: ,in represents the pruning threshold; Quantization compresses floating-point weights and activation values into a low-precision format (such as 8-bit integers), reducing the storage and computation requirements of the model. Train a complete model and convert the model's weights and activation values into a low-precision format. Fine-tune the quantized model to restore performance.
[0039] Set the float weight to ,but: , Represents the quantized weight, round represents the rounding operation, S is the scaling factor.
[0040] S5. Assign a unique feature vector as an identification mark to each segmented target image. The feature vector matches the individual animal. In subsequent target detection, once a target matching the feature vector is detected, it is identified, tracked and counted.
[0041] Specific processing flow: The processed original image is first sent to the YOLOv11-EMA target detection model to obtain a picture containing a target detection frame. Through the ROI multi-sensory attention method, the part containing only the target detection frame is sent to the SegFormer-Tiny model to accurately segment the target in the target detection frame, and assign a unique feature vector as an identification mark to each segmented object. The feature vector matches the individual animal. In the subsequent target detection, once a target that meets the feature vector is detected, it is identified, tracked and counted. When the target disappears from the field of view, the tracking is stopped, realizing real-time tracking and positioning of the animal.
[0042] The present invention can pair each detected target with a unique identifiable feature vector, realize real-time tracking and positioning of animals, and can help breeders to carry out refined management and effectively improve the economic benefits of breeding.
[0043] The above is only a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in various other combinations, modifications and environments, and can be modified within the scope of the concept described herein through the above teachings or the technology or knowledge of the relevant field. The changes and modifications made by those skilled in the art shall not deviate from the spirit and scope of the present invention, and shall be within the scope of protection of the claims attached to the present invention.
Claims
1. A method for real-time tracking and positioning of animals in a multi-target scene, characterized in that: include: S1, collect real-time data; S2, preprocessing the collected data; S3. Build a YOLOv11-EMA target detection model, input the processed data into the YOLOv11-EMA target detection model, and obtain a target image containing a target detection frame; S4, input the target image containing the target detection frame into the SegFormer-Tiny model, and segment the target image in the target detection frame; S5. Assign a unique feature vector as an identification mark to each segmented target image. The feature vector matches the individual animal. In subsequent target detection, once a target matching the feature vector is detected, it is identified, tracked and counted.
2. The method for real-time tracking and positioning of animals in a multi-target scene according to claim 1, characterized in that: Step S3 specifically includes: Add the EMA module to the tail of Backbone and Neck of the YOLOv11 target detection model at the same time to obtain the YOLOv11-EMA target detection model; The processed data is grouped by features, and the channel dimension of the input feature map is divided into G groups, each group contains C / G channels, and the grouping method is as follows: , where X is the input feature map, X i , i=1,2,...,G-1, represents the i-th channel group; The grouped data is fed into the parallel subnetwork. The EMA module processes the features through two parallel branches. The 1x1 convolution branch maps each set of features of X into space, preserving the local contextual relationship, as follows: , Represents the feature map after 1x1 convolution, Indicates a 1x1 convolution operation on the input feature map X; The 3x3 convolution branch captures local and multi-scale features in the following way: , Represents the feature map after 3x3 convolution, Indicates a 3x3 convolution operation on the input feature map X; Global average pooling is divided into global average pooling in two directions: horizontal and vertical, which capture global features in the horizontal and vertical directions respectively; , ; in, Indicates The first The eigenvalues at the positions, , Respectively represent the global average pooling results along the width and height directions, H represents the height of the feature map, and W represents the width of the feature map; The EMA module then aggregates the output features of the two parallel branches through a matrix dot product operation to capture the pairwise relationship at the pixel level and realize feature aggregation and interaction as follows: ; ; ; ; in, , as well as represents the intermediate variable, and It is the spatial attention map after adaptive average pooling and Softmax normalization. and is the transformation of the corresponding feature map, represents the matrix product of the feature map, weights is the final calculated weight map, b represents the batch size, and represents the number of samples in the current batch. is the number of feature groups, used to reduce computational complexity, Indicates combining batch and group. Represents the operation of reshaping the array. Finally, the EMA module applies the resulting weight map to the original tensor and reconstructs it into the original input shape.
3. The method for real-time tracking and positioning of animals in a multi-target scene according to claim 1, characterized in that: The SegFormer-Tiny model contains a multi-layer perceptron decoder; The decoder process steps are as follows: Unify the channel dimensions of multi-level features through a multi-layer perceptron layer; Upsample multi-level features to 1 / 4 resolution and concatenate them together; Use multi-layer perceptron layers to fuse the concatenated features and predict the fused features as segmentation masks; The calculation formula of EMA self-attention is: ; in They are query, key and value, is the dimension of each head, t represents the transpose operation, yes The transposed matrix of express Activation function.
4. The method for real-time tracking and positioning of animals in a multi-target scene according to claim 1, characterized in that: The SegFormer-Tiny model uses model pruning and quantization operations. Pruning removes redundant parameters and connections in the network, reducing the size and computation of the SegFormer-Tiny model as follows: Set the weight matrix to , the weight matrix after pruning is ,but: ,in represents the pruning threshold; The floating-point weights and activations are compressed by quantization to reduce the storage and computation requirements of the SegFormer-Tiny model as follows: , Represents the quantized weight, round represents the rounding operation, S is the scaling factor, It is a floating point weight.
5. The method for real-time tracking and positioning of animals in a multi-target scene according to claim 1, characterized in that: Step S2 specifically includes: using mosaic or mixup to perform data preprocessing.
6. A computer device comprising a memory, wherein the memory stores program instructions, characterized in that: When the program instructions are executed, the real-time animal tracking and positioning method in a multi-target scene as described in any one of claims 1 to 5 is executed.
Citation Information
Patent Citations
Free-range livestock group tracking and positioning method and device
CN117233695A
Layered multi-target tracking method based on significance detection
CN111027505A
Pedestrian multi-target tracking method combined with instance segmentation
CN116993775A
Reading identification method and system for pointer type instrument of substation equipment
CN117746025A
Cited By
Substation foreign matter intrusion detection method and system based on improved YOLOv11 model
CN119722662A
Computer program product, temporomandibular joint recognition device and temporomandibular joint recognition equipment
CN120411646A
Road signboard identification method and system based on deep learning
CN121033805A