Wild mammal behavior recognition method based on Gated Transformer network
By combining the Gated Transformer network and the DeepSnake model, the temporal and spatial characteristics of animal behavior are captured, solving the problem of insufficient animal behavior recognition accuracy and adaptability in the existing technology, and achieving high-precision recognition of wild mammal behavior, especially in Effective identification in complex environments.
Patent Information
- Application Number
- CN202210608011.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-31
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2042-05-31
AI Technical Summary
Existing animal behavior recognition methods based on a single image are difficult to achieve high-precision recognition, especially in complex backgrounds and extreme environments. Moreover, existing methods are mainly targeted at domestic animals and lack universality and adaptability.
A method based on the Gated Transformer network is used to capture temporal and spatial information through the parallel Transformer model, combined with DeepSnake to extract animal outline features, and use joint coordinate fluctuations to characterize different behaviors, and fuse temporal and spatial features for recognition.
It achieves high-precision recognition of wild mammal behaviors, improves recognition capabilities in complex backgrounds and extreme environments, and is universal, with an average accuracy of 96.8%.
Smart Images

Figure CN115035594B
Abstract
Description
Technical Field
[0001] The invention belongs to the field of image processing, and is an animal posture recognition method that integrates animal joint point coordinates and contour features, and is specifically a mammalian wild animal behavior recognition method based on a Gated Transformer network. Background Art
[0002] Wildlife resources are closely related to human life, but in recent years, the number of wildlife species has been decreasing, and many species are even on the verge of extinction. Wildlife zoos and national nature reserves play a very important role in protecting endangered wildlife. Understanding zoo or wildlife behavior can help maintain biodiversity and improve welfare for effective conservation.
[0003] The evolution of animal behavior recognition technology is as follows: the initial stage is manual observation and recording, and then sensors are fitted to animals. With the widespread application of infrared camera technology in wildlife diversity monitoring, image-based animal behavior recognition methods are gradually gaining attention and research.
[0004] Image-based animal behavior monitoring methods do not require external interference and have broad application prospects. However, existing methods extract spatial information or joint point topology based on a single image to identify animal behavior. In fact, some behaviors are very similar in spatial vision, such as standing and walking, which have similar spatial features or skeleton topology. Therefore, it is difficult to achieve high accuracy using only spatial information. In addition, animal behavior is a continuous process, so temporal information such as changes in bone topology can play an important role in animal recognition. In particular, the same behavior has similar bone topology even for different species, and bone sequence data is less affected by complex backgrounds.
[0005] Animal behavior recognition mainly involves extracting features that can distinguish different animal behaviors, using the extracted features as input, and then using corresponding classifiers to distinguish animal behaviors.
[0006] There are mainly two types of contour extraction methods based on deep convolutional networks: pixel-based methods and contour-based methods. Pixel-based methods are more common, such as MaskRCNN, FCN, etc. However, pixel-based methods require pixel-by-pixel detection and classify each pixel into foreground or background categories, which has high computational complexity and is easily affected by complex backgrounds.
[0007] Currently, many researchers are studying the problem of behavioral recognition of wild mammals by targeting small domestic or laboratory animals, and building specific recognition scenarios for specific animals. This is not universal and cannot identify the behavior of animals in extreme weather and complex environments. Summary of the invention
[0008] In order to solve the above technical problems, the present invention adopts a wild mammal behavior recognition model based on a Gated Transformer network to perform behavior recognition on images of wild mammals. The model can capture temporal and spatial information respectively through two parallel Transformers, namely, a channel-wise Transformer and a step-wise Transformer model. Therefore, the hidden correlations between different channels of the multivariate time series of wild mammal behavior classification can be utilized, and the self-attention mechanism in the network can be used to model the dependencies in the sequence.
[0009] Since the pixel-based object segmentation method cannot eliminate the influence of the background, the present invention uses the contour-based method DeepSnake to detect the animal contours in the image as spatial features, and then distinguishes the diversity of different behaviors of wild mammals in the temporal space by extracting the fluctuations of joint coordinates between consecutive frames, which helps to characterize the differences in the movement of joint points of different behaviors.
[0010] Finally, the temporal and spatial features are fused into a Gated Transformer network for action recognition of wild mammals.
[0011] Specifically, the wild mammal behavior recognition method based on the Gated Transformer network of the present invention first establishes a mammalian wild animal behavior recognition model, then uses the recognition model to process continuous frames of the input video clips, recognizes different behaviors of wild mammals, and finally outputs them.
[0012] The recognition model is based on the Gated Transformer network recognition model;
[0013] The steps of the identification method include:
[0014] 1) DeepLabCut software was used to mark the coordinates of the joint points of wild mammals in consecutive frames of a video clip as the temporal feature input of the network recognition model;
[0015] 2) Extract the outline of the wild mammal's body and calculate the perimeter, area, circularity, rectangularity and perimeter ratio of the outline as the spatial feature input of the network recognition model;
[0016] 3) inputting the temporal features and spatial features extracted in steps 1) and 2) into the recognition network model respectively to recognize different behaviors of wild mammals;
[0017] In the step 3):
[0018] 3.1) The coordinates of the joint points of the wild mammals marked in step 1) are used as the input of the Step-wise Transformer, the temporal branch of the Gated Transformer network;
[0019] 3.2) Using the Embedding layer and Multi-Head Attention layer of the temporal branched Step-wise Transformer to extract the temporal topology features of the joints of wild mammals;
[0020] 3.3) The features extracted by the Positional Embedding layer are stacked into the input layer of the Multi-Head Attention of the temporal branch Step-wise Transformer to enhance the temporal topological features of the joints of wild mammals extracted in step 3.2) so as to better distinguish the differences in the temporal topology of different behaviors;
[0021] 3.4) The perimeter, area, circularity, rectangularity and perimeter ratio of the wild mammal body part contour obtained in step 2) are used as input to the Channel-wise Transformer of the spatial branch of the Gated Transformer network;
[0022] 3.5) Multi-Head Attention of the spatial branch Channel-wise Transformer is used to capture the potential spatial feature correlation of wild mammals across different channels across all time steps to express the differences in contour features of different behaviors;
[0023] 3.6) Use Gate convolutional layer to fuse the spatiotemporal features of wild mammals extracted by Step-wise Transformer branch and Channel-wise Transformer branch;
[0024] 3.7) Use the Softmax layer to classify the feature vector flattened by the Linear layer into four behaviors: running, walking, sitting, lying, and standing.
[0025] Specifically, in step 1), DeepLabCut software is used to mark the coordinates of the joint points of wild mammals in a continuous frame of a video clip, and the steps include:
[0026] 1.1) Perform frame processing on the collected animal videos;
[0027] 1.2) Use DeepLabCut software to manually mark the joint locations of the animal body parts in the first few frames of a video;
[0028] 1.3) Use Ren-net101 for iterative training to predict the joint locations of all animal body parts.
[0029] In the step 2), the contour of the wild mammal body is extracted using the DeepSnake convolutional network, and the steps include:
[0030] 2.1) Using the convolutional network FCOS as the detector Decector of the DeepSnake convolutional network, the initial rectangular contours of the body parts of wild mammals are extracted, and the initial rectangular contours are used as the input of the DeepSnake convolutional network;
[0031] 2.2) Using DeepSnake convolutional network to approximate the initial contour multiple times, generating a contour that tightly surrounds the body part of the wild mammal;
[0032] 2.3) Calculate the perimeter, area, circularity, rectangularity and perimeter ratio of the outlines of body parts of wild mammals.
[0033] Specifically, the steps of step 2.2) include:
[0034] 2.2.1) Collect images of wild mammals in four behaviors: running, walking, sitting, lying, and standing, and label the images to create a dataset required for contour detection;
[0035] 2.2.2) Train the DeepSnake model’s detector to generate an initial rectangular positioning marker box for wild mammal targets;
[0036] 2.2.3) Take the midpoint of each side of the initial rectangular mark positioning box, connect the four midpoints to generate a diamond box;
[0037] 2.2.4) Input the diamond into the DeepSnake model and output the four extreme points of the predicted wild animal body parts;
[0038] 2.2.5) Extend the predicted pole as the center in the direction of the side to 1 / 4 of the length of the side to obtain the octagonal outline;
[0039] 2.2.6) N points are uniformly sampled from the extreme points of the octagonal contour, and are input into the DeepSnake model again. The output is N offsets from each vertex to the target boundary point. The contour is deformed by adding the offsets to its vertex coordinates. The deformed contour is used as the next iteration until the final contour segmentation map is obtained.
[0040] The steps of step 3.3) include:
[0041] 3.3.1) Considering that the joint point topology data and contour data of wild mammal behavior recognition are nonlinear, the Embedding layer uses a fully connected layer and a nonlinear activation function tanh;
[0042] 3.3.2) In order to extract the potential correlation of the features of different channels of the topological data and contour data of different behaviors of wild mammals in the GatedTransformer network, the Multi-Head Attention layer uses masked self-attention to focus on each point in all channels, and adopts a multi-scale dot product attention mechanism to obtain the multi-head self-attention matrix;
[0043] 3.3.3) Position-wise fully connected feed-forward layers are stacked on each multi-head attention layer for enhanced feature extraction.
[0044] The network structure used in step 3.5) is similar to that used in step 3.3).
[0045] In the step 3.6):
[0046] 3.6.1) The function of the Gate convolution layer is to fuse the contour features of wild mammals extracted by the Channel-wise Transformer branch and the temporal topological features of joint points extracted by the Step-wise Transformer branch, and use the Gating gating mechanism to learn the weights of each Transformer branch;
[0047] 3.6.2) Each Gating weight participates in the output of the Transformer branch, and the Linear layer flattens the fused features into a feature vector through linear mapping.
[0048] The present invention has the following technical features:
[0049] (1) A wild mammal behavior recognition model based on the Gated Transformer network is proposed. The model can capture spatial and temporal features respectively through two parallel Transformers. The multi-head attention mechanism of wild mammal behavior classification is used to extract the potential correlation between features in different channels. At the same time, the self-attention mechanism in the network is used to model the dependencies in the sequence. The recognition model is used to recognize wild mammal images in continuous frames of the collected video clips.
[0050] (2) DeepSnake is used to extract the contour features of animals, avoiding the problem of being unable to obtain the contour of the object due to inaccurately marked rectangular boxes. At the same time, compared with the contour extraction method based on pixel-based deep convolutional networks, this strategy has obvious advantages in contour detection speed.
[0051] (3) The fluctuations of joint coordinates during consecutive frames are used as temporal features to express the temporal information of different behaviors of wild mammals and to characterize the differences in joint movement speed between different behaviors. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 This is a convolutional network structure diagram for wild mammal behavior recognition of the present invention.
[0053] Figure 2 This is the curve of the experimental accuracy. DETAILED DESCRIPTION
[0054] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments.
[0055] The wild mammal behavior recognition method based on the Gated Transformer network of the present invention first uses DeepLabCut to define the positions of various joints of the animal to construct the skeleton diagram of the animal, and tracks the coordinates of the joints of the wild animal in motion through training, and determines the coordinates of the joints by tracking the joints of the body parts as a time series feature of motion detection, and puts the time series feature into the step-wise channel for training;
[0056] At the same time, Deepsnake is used to extract the contours of wild mammals. The perimeter, area, circularity, rectangularity and perimeter ratio of the extracted contours are calculated as time series contour features and put into the Channel-Wise channel for training.
[0057] Finally, the Step-wise channel and Channel-wise channel are merged and connected to the gating link, and the behavior of wild animals is classified through Softmax.
[0058] Specific reference Figure 1 , the steps of this embodiment include:
[0059] Step 1: For the collected videos of wild mammals, first convert the videos into video frames, use clustering algorithms to remove a large number of redundant images, and select key frames of four typical behaviors: running, sitting, standing and walking.
[0060] Step 2: Use DeepLabCut to track the positions of the joints of the animal's body parts in the collected video frames to form the animal's skeleton diagram. The specific steps are as follows:
[0061] Step 2.1, manually mark the positions of 18 joint points of each body part of a few frames of animal images;
[0062] Step 2.2, taking the image of wild mammals as input, iteratively train through Res-net101 to obtain the coordinate information of the joint points of the wild mammals' body parts and the confidence of each joint point;
[0063] Step 2.3, calculate the joint point position y manually marked in step 2.1 and the network prediction result in step 2.2 The mean square error is used to measure the correctness of the network;
[0064] The coordinates of the animal's joint points are taken as input, and are weightedly connected to the multi-head attention, residual network, feedforward network, etc. Step-wise channels through the embedding layer and the position embedding layer to distinguish the behavior recognition of wild mammals.
[0065] Step 3: Convert the collected wildlife videos into video frames and use the Deepsnake model to extract the outlines of wild mammals. The specific steps are as follows:
[0066] Step 3.1: Put the selected images of wild mammals into the Deepsnake network and reduce the scale of training through pre-training models and transfer learning.
[0067] Step 3.2, in order to obtain the contour of the image, it is divided into two stages, initial contour generation and contour deformation. First, an octagonal contour is used to tightly surround the object as the initial contour. The octagon is composed of four extreme points of the pixels at the top, leftmost, bottom, and rightmost of the object to form a diamond contour.
[0068] In step 3.3, N points are then uniformly sampled from the extreme points of the diamond contour. After the initial contour is input, the output is N offsets from each vertex to the target boundary point. The contour is deformed by adding the offset to its vertex coordinates, and the deformed contour is used as the next iteration until the final contour segmentation map is obtained.
[0069] In step 4, the joint coordinates of the wild animal in step 2 are weighted through the embedding layer and the position embedding layer, connected to the Step-wise channel, and the contour features extracted and calculated by Deepsnake in step 3 are connected to the Channel-wise channel through the embedding layer. Then the Step-wise output and the Channel-wise output are merged into the gating network, and finally the animal behavior is classified through Softmax to obtain the final result.
[0070] During the experiment:
[0071] 1. Dataset
[0072] A dataset containing dozens of wild mammals is used. Some video sequences are collected and labeled using a Python script adapted from a web scraping tool created by HardikVasa. The dataset includes four behaviors: sitting, standing, running, and walking. During the experiment, it was found that contour detection is easily affected by the background, so the undetected contours of the current frame are replaced with those of the previous frame.
[0073] 2. Implementation Configuration
[0074] Training and testing were performed using an Nvidia Quadro K2200 GPU with 4GB 221 graphics memory, 64GB RAM and an Intel Xeon (R) W2123, 4.00GHz CPU. The programs all used Python, PyTorch, and Tensorflow to build and train the network. The DeepSnake model was used to draw the outline of the animal using the Pytorch model as well as transfer learning. The animal's skeletal information was annotated using Deeplabcut and Tensorflow models and Res-Net model training. GatedTransformer is also based on a PyTorch detection model. Three indicators, including accuracy, recall, and precision, are used to evaluate performance.
[0075] 3. Parameter settings
[0076] The Adam optimizer is used to optimize the algorithm for the spatiotemporal network, and the learning rate of each parameter is adjusted to stabilize the parameter changes. The learning rate is set to 0.0001 and dropout = 0.2. Categorical cross entropy is used as the loss function.
[0077] 4. Experimental results
[0078] Feature evaluation
[0079] To evaluate the extracted features, ablation experiments were performed on three features: joint coordinates, contour features, and knee angle. As shown in Table 1, joint coordinates perform best in distinguishing mammalian behaviors because the fluctuation of joint coordinates can represent the movement speed of different behaviors, such as standing, running, and walking. Knee angle is mainly used to classify static and dynamic behaviors, while contour features can effectively distinguish between sitting and standing. However, whether knee angle or contour features are used alone, the classification results are not satisfactory. Therefore, these two features are used as auxiliary features.
[0080] Table 1 Comparison of three features
[0081]
[0082] Convergence analysis
[0083] exist Figure 2 The accuracy curve is depicted in Figure 2 As shown in Figure 2, the loss function begins to converge after step 6500. Excellent results can be achieved on both the training set and the test set.
[0084] Comparative analysis of experimental results
[0085] This experiment compares the proposed network model with the LSTM network. LSTM (Long Short-Term Memory) is a classic network for time series prediction. In the experiment, LSTM has the same input features as the proposed method.
[0086] The classification results are shown in Table 2. The model proposed in this invention is obviously better than the LSTM model.
[0087] Table 2 Comparison of two different methods
[0088]
[0089] Experiments show that the proposed model can effectively identify four representative behaviors of animals: running, sitting, walking and standing. The average accuracy of the scheme for identifying wild mammal behaviors reaches 96.8%.
[0090] The main technical effects of this method include:
[0091] (1) The Deepsnake model is used to extract the outlines of wild mammals, which can avoid false detections caused by the influence of trees, flowers and plants in complex backgrounds and weather in extreme environments.
[0092] (2) Construct a posture classification network for wild mammals, namely the Gated Transformer network, and use Channel-wise and Step-wise learning of animal features corresponding to time and space channels respectively to classify animal behaviors.
[0093] (3) DeepLabCut is used to quickly track the changes in the positions of the joints of the marked animal body parts as one of the features, and as a temporal feature for animal behavior classification to distinguish the animal's behavior, which increases the robustness of the algorithm.
[0094] (4) Based on the model with contour information as the spatial feature of the network input, the body joint point information and contour features are put into the Gated transformer classification network, which can effectively improve the recognition accuracy.
Claims
1. A wild mammal behavior recognition method based on a Gated Transformer network, firstly establishing a wild mammal behavior recognition model, then using the recognition model to process the continuous frames of the input video clips, and recognize the different behaviors of wild mammals, and finally outputting, which is characterized by The recognition model is based on the Gated Transformer network recognition model; The steps of the identification method include: 1) Mark the coordinates of the joints of wild mammals in consecutive frames of a video clip as the temporal feature input of the network recognition model; 2) Extract the outline of the wild mammal's body and calculate the perimeter, area, circularity, rectangularity and perimeter ratio of the outline as the spatial feature input of the network recognition model; 3) inputting the temporal features and spatial features extracted in steps 1) and 2) into the recognition network model respectively to recognize different behaviors of wild mammals; In the step 3): 3.1) The coordinates of the joint points of the wild mammals marked in step 1) are used as the input of the Step-wise Transformer, the temporal branch of the Gated Transformer network; 3.2) Using the Embedding layer and Multi-Head Attention layer of the temporal branched Step-wise Transformer to extract the temporal topology features of the joints of wild mammals; 3.3) The features extracted by the Positional Embedding layer are stacked into the input layer of the Multi-Head Attention of the temporal branch Step-wise Transformer to enhance the temporal topological features of the joints of wild mammals extracted in step 3.2) so as to better distinguish the differences in the temporal topology of different behaviors; 3.4) The perimeter, area, circularity, rectangularity and perimeter ratio of the wild mammal body part contour obtained in step 2) are used as input to the Channel-wise Transformer of the spatial branch of the Gated Transformer network; 3.5) Multi-Head Attention of the spatial branch Channel-wise Transformer is used to capture the potential spatial feature correlation of wild mammals across different channels across all time steps to express the differences in contour features of different behaviors; 3.6) The Gate convolution layer is used to fuse the temporal features of wild mammals extracted by the Step-wise Transformer branch and the spatial features of wild mammals extracted by the Channel-wise Transformer branch; 3.7) Use the Softmax layer to classify the feature vector flattened by the Linear layer into four behaviors: running, walking, sitting, lying, and standing.
2. The wild mammal behavior recognition method based on the Gated Transformer network according to claim 1, characterized in that In the step 1), DeepLabCut software is used to mark the coordinates of the joint points of wild mammals in a continuous frame of a video clip, and the steps include: 1.1) Perform frame processing on the collected animal videos; 1.2) Use DeepLabCut software to manually mark the joint locations of the animal body parts in the first few frames of a video; 1.3) Use Res-net101 for iterative training to predict the joint locations of all animal body parts.
3. The wild mammal behavior recognition method based on the Gated Transformer network according to claim 1, characterized in that In the step 2), the contour of the wild mammal body is extracted using the DeepSnake convolutional network, and the steps include: 2.1) Using the convolutional network FCOS as the detector of the DeepSnake convolutional network, the initial rectangular contours of the body parts of wild mammals are extracted and the initial rectangular contours are used as the input of the DeepSnake convolutional network; 2.2) Using DeepSnake convolutional network to approximate the initial contour multiple times, generating a contour that tightly surrounds the body part of the wild mammal; 2.3) Calculate the perimeter, area, circularity, rectangularity and perimeter ratio of the outlines of body parts of wild mammals; Specifically, the steps of step 2.2) include: 2.2.1) Collect images of wild mammals in four behaviors: running, walking, sitting, lying, and standing, and label the images to create a dataset required for contour detection; 2.2.2) Train the DeepSnake model’s detector to generate an initial rectangular positioning marker box for wild mammal targets; 2.2.3) Take the midpoint of each side of the initial rectangular mark positioning box, connect the four midpoints to generate a diamond box; 2.2.4) Input the diamond into the DeepSnake model and output the four extreme points of the predicted wild animal body parts; 2.2.5) Extend the predicted pole as the center in the direction of the side to 1 / 4 of the length of the side to obtain the octagonal outline; 2.2.6) N points are uniformly sampled from the extreme points of the octagonal contour, and are input into the DeepSnake model again. The output is N offsets from each vertex to the target boundary point. The contour is deformed by adding the offsets to its vertex coordinates. The deformed contour is used as the next iteration until the final contour segmentation map is obtained.
4. The wild mammal behavior recognition method based on the Gated Transformer network according to claim 1, characterized in that The steps of step 3.3) include: 3.3.1) Considering that the joint point topology data and contour data of wild mammal behavior recognition are nonlinear, the Embedding layer uses a fully connected layer and a nonlinear activation function tanh; 3.3.2) In order to extract the potential correlation of the features of different channels of the topological data and contour data of different behaviors of wild mammals in the GatedTransformer network, the Multi-Head Attention layer uses masked self-attention to focus on each point in all channels, and adopts a multi-scale dot product attention mechanism to obtain the multi-head self-attention matrix; 3.3.3) Position-wise fully connected feed-forward layers are stacked on each multi-head attention layer for enhanced feature extraction.
5. The method for identifying wild mammal behavior based on a Gated Transformer network according to claim 1, characterized in that The steps of step 3.6) include: 3.6.1) The function of the Gate convolution layer is to fuse the contour features of wild mammals extracted by the Channel-wise Transformer branch and the temporal topological features of joint points extracted by the Step-wise Transformer branch, and use the Gating gating mechanism to learn the weights of each Transformer branch; 3.6.2) Each Gating weight participates in the output of the Transformer branch. The Linear layer flattens the fused features into a feature vector through linear mapping, which is classified by the Softmax layer.
