A video behavior recognition method and system
Through the pre-trained spatiotemporal feature extraction and set matching modules, combined with the Hausdorff distance loss function, the problem of dependence on annotated data and long inference time in video behavior recognition is solved, and efficient small-sample video behavior recognition is achieved.
Patent Information
- Application Number
- CN202210163283.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-22
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2042-02-22
AI Technical Summary
Existing video behavior recognition algorithms rely on a large amount of annotated data and require long inference times, and small-sample behavior recognition methods are ineffective when dealing with timing offsets and sub-action flips.
The pre-trained spatiotemporal feature extraction module and set matching module are used to achieve video behavior recognition through the spatiotemporal feature extraction and matching module, combined with the Hausdorff distance loss function, reducing training and inference time, and adapting to small sample scenarios.
It improves the accuracy and efficiency of video behavior recognition, can effectively match the similarities between video frames, is suitable for small sample scenarios, and reduces training and inference costs.
Smart Images

Figure CN114581819B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of video behavior recognition, and more specifically, relates to a video behavior recognition method and system. Background Art
[0002] Deep learning video models have achieved remarkable results in recent years, but most of the current deep learning algorithms rely heavily on a large amount of labeled video data to acquire knowledge. In this context, the problem of small sample behavior recognition has become one of the important research directions in the field of deep learning. Small sample behavior recognition means that given a video to be tested, a small amount of template videos can be used to match and classify the video. Compared with traditional behavior recognition driven by a large number of samples, small sample behavior recognition requires accurate recognition using a small amount of video data, so it is more in line with real application scenarios.
[0003] The first small sample behavior recognition methods are mainly based on metric learning. This type of method maps the input video to a feature space through a feature extraction network, and involves some complex alignment modules in this feature space to match the video. For example, the article "Few-shot video classification via temporal alignment, Proceedings of the IEEE / CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2020: 10618-10627." designed a complex dynamic temporal alignment model to match videos.
[0004] Existing small-sample action recognition methods require complex timing alignment operations, which have two limitations: (1) training and inference are extremely time-consuming and are not suitable for scenarios requiring fast inference; (2) they place too much emphasis on timing alignment and are not applicable to instances with timing offsets and sub-action flips. Summary of the invention
[0005] In view of the defects of the prior art, the purpose of the present invention is to provide a video behavior recognition method and system, aiming to solve the problems that the existing video behavior recognition algorithms require a large amount of labeled video sample data, and it is difficult to obtain a large number of samples for some video samples; and the existing small sample behavior recognition methods have too high inference time costs and over-emphasis on timing alignment.
[0006] To achieve the above object, in a first aspect, the present invention provides a video behavior recognition method, comprising the following steps:
[0007] Determine a pre-trained recognition network; the recognition network includes: a spatiotemporal feature extraction module and a set matching module; the spatiotemporal feature extraction module is used to extract the spatial features and temporal features of the received video, and the set matching module is used to match the received video with the template video based on the spatial features and temporal features and the spatiotemporal features of the template video to identify the behavior of the received video; the template video includes T categories of videos, and different categories of videos correspond to different behaviors, and the spatiotemporal features of each category of video in the template video are known; when training the recognition network, randomly select S categories of videos from the T categories of videos in a loop, determine K training samples for each category of video, and input the training samples corresponding to the S categories of videos into the recognition network for training, S is less than T, and K is less than a preset value;
[0008] The video to be identified and the template video are input into the pre-trained recognition network to perform behavior recognition on the video to be identified and output the corresponding behavior recognition result.
[0009] In an optional example, the spatiotemporal feature extraction module is used to extract spatial features and temporal features of a received video, specifically including: the spatiotemporal feature extraction module extracts a feature sequence retained in the spatial and temporal dimensions of the received video; performs spatial feature modeling on the feature sequence, and obtains the spatial relationship within the video frame based on the gated recurrent unit and the features after spatial modeling as the spatial features of the received video; performs temporal feature modeling on the features after spatial modeling, and extracts the long-range temporal dependencies between video frames based on the gated recurrent unit and the features after temporal modeling as the temporal features of the received video.
[0010] In an optional example, the set and matching module is used to match the received video with the template video based on the spatial features and temporal features and the spatiotemporal features of the template video, specifically including: the set and matching module models the spatial features and temporal features to obtain features with enhanced spatiotemporal relationships; based on the features with enhanced spatiotemporal relationships and the spatiotemporal features of the template video, using the correspondence between the videos to obtain the matching similarity between the received video and the template video; based on the matching similarity, determining which video in the received video and the template video is the most matched, and determining the behavior of the received video according to the behavior of the matched video.
[0011] In an optional example, the overall loss function L of the recognition network is:
[0012] L=λL label +L sim
[0013] Among them, L label is the classification loss of the real labels of the video to be detected and the template video; L simis the metric loss based on matching similarity; λ is the balance coefficient, which is used to balance the two loss functions;
[0014]
[0015]
[0016]
[0017]
[0018]
[0019]
[0020] L sim =L ce (D,y)
[0021] in, Represents the feature sequence of the template video in the video library, Represents the characteristics of the sample video to be tested; Representing video features To video features The Hausdorff distance; Representing video features To video features The Hausdorff distance; Video The ath feature in , that is, the feature corresponding to the ath frame of the video; Video The qth feature in the video is the feature corresponding to the qth frame of the video; N i is the number of frames of one of the template videos; N q represents the number of frames of the sample video to be tested; N represents the number of all videos in each training batch; L ce is the cross entropy loss function; and i They represent the behavior category predicted by the model and the real behavior category respectively; D represents the predicted similarity of the video sample to be tested; Representing video features To video features One-way modified Hausdorff distance; D b represents the bidirectional modified Hausdorff distance.
[0022] In a second aspect, the present invention provides a video behavior recognition system, comprising:
[0023] A recognition network pre-training unit is used to determine a pre-trained recognition network; the recognition network includes: a spatiotemporal feature extraction module and a set matching module; the spatiotemporal feature extraction module is used to extract the spatial features and temporal features of the received video, and the set matching module is used to match the received video with the template video based on the spatial features and temporal features and the spatiotemporal features of the template video to identify the behavior of the received video; the template video includes T categories of videos, and different categories of videos correspond to different behaviors, and the spatiotemporal features of each category of video in the template video are known; when training the recognition network, S categories of videos are randomly selected from the T categories of videos in a loop, K training samples are determined for each category of video, and the training samples corresponding to the S categories of videos are input into the recognition network for training, S is less than T, and K is less than a preset value;
[0024] The behavior recognition unit is used to input the video to be recognized and the template video into the pre-trained recognition network to perform behavior recognition on the video to be recognized and output the corresponding behavior recognition result.
[0025] In an optional example, the spatiotemporal feature extraction module is used to extract spatial features and temporal features of a received video, specifically including: the spatiotemporal feature extraction module extracts a feature sequence retained in the spatial and temporal dimensions of the received video; performs spatial feature modeling on the feature sequence, and obtains the spatial relationship within the video frame based on the gated recurrent unit and the features after spatial modeling as the spatial features of the received video; performs temporal feature modeling on the features after spatial modeling, and extracts the long-range temporal dependencies between video frames based on the gated recurrent unit and the features after temporal modeling as the temporal features of the received video.
[0026] In an optional example, the set and matching module is used to match the received video with the template video based on the spatial features and temporal features and the spatiotemporal features of the template video, specifically including: the set and matching module models the spatial features and temporal features to obtain features with enhanced spatiotemporal relationships; based on the features with enhanced spatiotemporal relationships and the spatiotemporal features of the template video, using the correspondence between the videos to obtain the matching similarity between the received video and the template video; based on the matching similarity, determining which video in the received video and the template video is the most matched, and determining the behavior of the received video according to the behavior of the matched video.
[0027] In an optional example, the overall loss function L of the recognition network is:
[0028] L=λL label +L sim
[0029] Among them, L label is the classification loss of the real labels of the video to be detected and the template video; Lsim is the metric loss based on matching similarity; λ is the balance coefficient, which is used to balance the two loss functions;
[0030]
[0031]
[0032]
[0033]
[0034]
[0035]
[0036] L sim =L ce (D,y)
[0037] in, Represents the feature sequence of the template video in the video library, Represents the characteristics of the sample video to be tested; Representing video features To video features The Hausdorff distance of Representing video features To video features The Hausdorff distance of Video The ath feature in , that is, the feature corresponding to the ath frame of the video; Video The qth feature in the video is the feature corresponding to the qth frame of the video; N i is the number of frames of one of the template videos; N q represents the number of frames of the sample video to be tested; N represents the number of all videos in each training batch; L ce is the cross entropy loss function; and i They represent the behavior category predicted by the model and the real behavior category respectively; D represents the predicted similarity of the video sample to be tested; Representing video features To video features One-way modified Hausdorff distance; D b represents the bidirectional modified Hausdorff distance.
[0038] In general, the above technical solution conceived by the present invention has the following beneficial effects compared with the prior art:
[0039] The present invention provides a video behavior recognition method and system. When training a small sample behavior recognition network model, a video to be tested and a small amount of template videos in a video library are input, and a spatiotemporal feature extraction network is used to realize joint modeling of spatial relationship modeling of frames inside the input video and temporal relationship modeling between video frames. By capturing the rich spatiotemporal dependencies inside the video, discriminative features can be learned, which is more helpful to distinguish different videos and match the same video.
[0040] The present invention provides a video behavior recognition method and system, and provides a set matching metric module to train a small sample behavior recognition model. By flexibly matching the similarity of frame-level features, the correspondence between video frames in two videos can be effectively found, thereby effectively matching the videos. At the same time, the set matching metric module is a parameter-free metric method, which can effectively accelerate the training and reasoning process.
[0041] The present invention provides a video behavior recognition method and system, and provides a small sample behavior recognition network model based on set matching, including a loss function based on real action categories and a consistency loss function based on the similarity between video instances. The main purpose is to expand the distance between samples of different categories in the learned feature space, and at the same time reduce the distance between samples of the same category, so that the learned feature space category separability is good. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 is a flow chart of a video behavior recognition method provided by an embodiment of the present invention;
[0043] Figure 2 is a flow chart of a specific video behavior recognition method provided by an embodiment of the present invention;
[0044] Figure 3 is a neural network structure diagram provided by an embodiment of the present invention;
[0045] Figure 4 It is a diagram of the architecture of a video behavior recognition system provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0047] The present invention provides a video behavior recognition method and system, which belongs to the field of behavior recognition under artificial intelligence limited sample conditions. The method of the present invention comprises: inputting a video of unknown category to be detected and a template video in a video library into a spatiotemporal feature extraction module to obtain frame-level features of the video to be detected and frame-level features of the template video in the video library; calculating the similarity between the video to be detected and the video in the video library by using a set matching algorithm to obtain a matching result of the video to be detected, and then obtaining the behavior category of the video to be detected. The method for training the entire network framework is: constructing a framework of a spatiotemporal feature extraction network; using the video to be detected and the template video in the video library as inputs of a target search network model, using a spatial feature fusion and a temporal feature fusion method to construct a feature extraction network model that can generate discriminative spatiotemporal features; using the generated discriminative spatiotemporal features as inputs of a set matching module, performing flexible frame-level matching on two videos, and finally obtaining a matching result. In a small sample scenario, the present invention makes full use of the spatial and temporal relationships within the video to generate discriminative spatiotemporal representations, and uses a parameter-free set matching strategy to achieve flexible and accurate video matching and recognition.
[0048] To achieve the above object, on the one hand, the present invention provides a small sample behavior recognition method based on set matching, comprising the following steps:
[0049] Input the video to be detected and the template video in the video library into the trained spatiotemporal feature extraction module to obtain the discriminative frame-level spatiotemporal features of the video to be detected and the frame-level spatiotemporal features of all template videos in the video library;
[0050] Using a set matching module to calculate the similarity between the features of the video to be tested and the features of the template video in the video library, obtaining a matching result of the video to be tested, and finally obtaining a behavior category;
[0051] The method for training the entire small sample behavior recognition model includes the following steps:
[0052] (1) Construct a framework for a small sample behavior recognition network model based on set matching;
[0053] The entire recognition network is divided into a spatiotemporal feature extraction module and a set matching metric module, wherein the set matching metric module acts on the discriminative spatiotemporal features generated by the spatiotemporal feature extraction module;
[0054] (2) The original video to be tested and the template video in the video library of each task are used as inputs of a small sample behavior recognition network model based on set matching, and a modeling method based on the spatial and temporal dimensions of the video is used to generate a discriminative spatiotemporal feature sequence; wherein the feature modeling method includes spatial correlation modeling and temporal correlation modeling for each frame of the video;
[0055] Then, the ensemble matching metric module takes the generated discriminative spatiotemporal feature sequence as input and improves the parameter-free Hausdorff distance to perform accurate video matching;
[0056] (3) The overall loss function of the small sample behavior recognition network model based on set matching is constructed using the supervisory signal of the correspondence between the original video to be tested and the template video in the video library, so that the video features of the same category are close to each other and the video features of different categories are far away from each other; when the overall loss function of the network model converges, it is determined that the entire network training is completed and can be used for testing.
[0057] Preferably, the spatial and temporal modeling method of the video is combined with the spatiotemporal feature extraction module, specifically comprising the following steps:
[0058] The original video is input into the network model, and the feature extraction network obtains the feature sequence preserved in the spatial dimension and the temporal dimension;
[0059] The obtained feature sequence is spatially modeled, and the spatial relationship within the video frame is obtained based on the gated recurrent unit (GRU);
[0060] Temporal feature modeling is performed for the features after spatial modeling, and the long-range temporal dependencies between video frames are extracted based on the gated recurrent unit GRU;
[0061] Preferably, the set matching metric module is used to perform accurate and flexible video matching, which specifically includes the following steps:
[0062] The original video is input into the network model, and the feature extraction network obtains the feature sequence preserved in the spatial dimension and the temporal dimension, and then the relationship between the spatial dimension and the temporal dimension is modeled to obtain the features with enhanced spatiotemporal relationship;
[0063] Based on the enhanced features of spatiotemporal relationships, a set matching-based measurement module is established to accurately obtain the matching similarity using the corresponding relationship between videos;
[0064] The loss function based on similarity measurement and the cross entropy loss function based on true categories are combined to construct the overall loss function of the small sample behavior recognition model based on set matching.
[0065] Preferably, the overall loss function of the small sample behavior recognition network model based on set matching is:
[0066] L=λL label +L sim
[0067] Among them, L labelis the classification loss of the real labels of the video to be detected and the template video in the video library; L sim is the metric loss based on similarity; λ is the balance coefficient, which is used to balance the two loss functions;
[0068]
[0069]
[0070]
[0071]
[0072]
[0073]
[0074] L sim =L ce (D,y)
[0075] in, Represents the feature sequence of the template video in the video library, Represents the characteristics of the sample video to be tested; N i is the number of frames of one of the template videos; N q represents the number of frames of the sample video to be tested; N represents the number of all videos in each training batch; L ce is the cross entropy loss function; and i They represent the action category predicted by the model and the actual action category respectively; D represents the predicted similarity of the video sample to be tested. If they match, the similarity should be large; if they do not match, the similarity should be small.
[0076] On the other hand, the present invention provides a small sample behavior recognition device based on set matching, comprising: a spatiotemporal feature extraction module, a set matching metric module, a loss function construction module and a training determination module;
[0077] The small sample behavior recognition network module is used to input the video to be tested and the template video in the video library into the spatiotemporal feature extraction network model under the trained small sample condition, firstly obtaining the extracted features of the video to be tested and the features of all the template videos in the video library;
[0078] The obtained video features are subjected to spatial feature modeling and temporal relationship modeling operations to obtain a more discriminative spatiotemporal video feature sequence, which is specifically obtained by obtaining spatial and temporal context information through the gated recurrent unit GRU to obtain more robust features;
[0079] The set matching metric module is used to calculate the similarity between the features of the video to be tested and the template video in the video library, obtain the matching result of the video to be tested, and then perform behavior classification;
[0080] The loss function construction module is used to construct the overall loss function of the small sample behavior recognition network model with the supervision signal of the real category and the matching signal of whether the category is the same;
[0081] The training judgment module is used to consider that the network training of the small sample behavior recognition network model is completed when the overall loss function of the small sample behavior recognition network model converges, and the small sample behavior recognition network model can be used for testing.
[0082] Preferably, the spatial and temporal modeling method of the video is combined with the spatiotemporal feature extraction module, specifically comprising the following steps:
[0083] The original video is input into the network model, and the feature extraction network obtains the feature sequence preserved in the spatial dimension and the temporal dimension;
[0084] The obtained feature sequence is subjected to spatial feature modeling, and the spatial relationship within the video frame is obtained based on the gated recurrent unit;
[0085] Temporal feature modeling is performed for the features after spatial modeling, and the long-range temporal dependencies between video frames are extracted based on the gated recurrent unit GRU;
[0086] Preferably, the set matching metric module is used to perform accurate and flexible video matching, which specifically includes the following steps:
[0087] The original video is input into the network model, and the feature extraction network obtains the feature sequence preserved in the spatial dimension and the temporal dimension, and then the relationship between the spatial dimension and the temporal dimension is modeled to obtain the features with enhanced spatiotemporal relationship;
[0088] Based on the enhanced features of spatiotemporal relationships, a set matching-based measurement module is established to accurately obtain the matching similarity using the corresponding relationship between videos;
[0089] The loss function based on similarity measurement and the cross entropy loss function based on true categories are combined to construct the overall loss function of the small sample behavior recognition model based on set matching.
[0090] Figure 1 is a flow chart of a video behavior recognition method provided by an embodiment of the present invention. Figure 1 As shown, the following steps are included:
[0091] S101, determine a pre-trained recognition network; the recognition network includes: a spatiotemporal feature extraction module and a set matching module; the spatiotemporal feature extraction module is used to extract the spatial features and temporal features of the received video, and the set matching module is used to match the received video with the template video based on the spatial features and temporal features and the spatiotemporal features of the template video to identify the behavior of the received video; the template video includes T categories of videos, and different categories of videos correspond to different behaviors, and the spatiotemporal features of each category of video in the template video are known; when training the recognition network, randomly select S categories of videos from the T categories of videos in a loop, determine K training samples for each category of video, and input the training samples corresponding to the S categories of videos into the recognition network for training, S is less than T, and K is less than a preset value;
[0092] S102, inputting the video to be identified and the template video into a pre-trained recognition network to perform behavior recognition on the video to be identified, and outputting a corresponding behavior recognition result.
[0093] The present invention deals with small sample behavior recognition tasks. Compared with traditional behavior recognition tasks, small sample behavior recognition aims to achieve accurate matching and recognition using a small number of samples. The small sample behavior recognition method constructs two data sets, namely a base category set and a novel category set, where the behavior categories in the base category set and the novel category set have no intersection. The designed network model is trained on the base category set and tested on the novel category set. When testing on the novel category set, only a small number of template videos are provided for each category, generally 1 to 5. If 5 categories are provided, 1 sample for each category is called a 5-way 1-shot task; if 5 categories are provided, 5 samples for each category is called a 5-way 5-shot task; therefore, in order to make the training and testing scenarios the same, a large number of small sample tasks are constructed during training. A task is called an episode. During training, each task will contain template videos in the video library. If it is a 5-way 1-shot task, 5 behavior categories are randomly selected from the video library, and 1 video is selected from each category as a template video. The video to be tested is randomly obtained from other videos in these 5 behavior categories. During the test, only the behavior category of the template video is known. The video to be tested is matched with the template video by similarity, and the template video with the greatest similarity is selected. The behavior category of the template video is assigned to the video to be tested, and then the recognition of the video to be tested is completed.
[0094] like Figure 2 As shown, this embodiment provides a specific video behavior recognition method, including the following steps:
[0095] (1) Setting up behavior recognition in small sample scenarios;
[0096] The general principle of deep learning is to use a large amount of labeled data for training and learning, and to learn a statistical model to make predictions about the same category of data in the future. In this case, the generalization and migration capabilities of the model need to be guaranteed by sufficient labeled data. This limits our practical application. In many practical application scenarios, in most cases, we are only allowed to use a small amount of training video data about new action categories as a reference. Under this restriction, each new action category may have only one or a few labeled examples. For example, in the behavior scenario of abnormal behavior detection, we may only be able to provide a small number of behavior categories such as fighting, but in order to protect the safety of people's lives and property, we must accurately identify these action categories. This embodiment provides a behavior recognition method in a small sample scenario, which can identify new categories using only a small number of action category examples. During the training process, we simulate the test process and construct many small sample tasks (episodes). In each episode, there is a support set (supportset) and a query video, where each support set contains some template videos; if in an episode, the support set contains N action categories and each action category contains K samples, then we call such a task an N-wayK-shot task; during training, we will sample a large number of such small sample tasks to learn the network so that the network can adapt to the small sample environment;
[0097] (2) Construct a framework for behavior recognition network models in small sample scenarios;
[0098] like Figure 3 As shown in the figure, the support set video and the video to be tested are input. The behavior recognition network framework contains two modules, namely, the spatiotemporal feature extraction module and the set matching measurement module. The spatiotemporal feature extraction module is used to encode the input video features, and the weights are shared for different input videos. The set matching measurement module acts on the encoded video features for flexible matching.
[0099] (3) The original video to be tested and the template video in the video library of each task are used as inputs of a small sample behavior recognition network model based on set matching, and a modeling method based on the spatial and temporal dimensions of the video is used to generate a discriminative spatiotemporal feature sequence; wherein the feature modeling method includes spatial correlation modeling and temporal correlation modeling for each frame of the video; then, the set matching metric module uses the generated discriminative spatiotemporal feature sequence as input and improves the parameter-free Hausdorff distance to perform accurate video matching;
[0100] Specifically, in the spatiotemporal feature extraction module, this embodiment uses ResNet-50 as the cornerstone of the feature extraction network and uses the pre-trained weights on ImageNet as initialization; since the last layer of ResNet-50 is a classifier, the classifier layer is removed here, and the features before the last Average-pooling layer are output. The dimension of the single video feature f obtained here is T×W f ×H f ×C f , where T is the time length, W f is the width of the feature, H f is the height of the feature, C f is the number of channels of the feature. In this embodiment, ResNet-50 is used as the feature extractor. f =H f =3, C f =2048;
[0101] After obtaining the features through the feature extractor, the spatial feature modeling operation is used to capture the rich spatial context information inside the video frame. Specifically, the video features are first serialized and then input into the gated recurrent unit (GRU) to model the relationship between spatial features. The entire spatial feature modeling process is expressed as follows: First, a single video feature f: T×W f ×H f ×C f Serialize to T×W f H f ×C f , and then input into GRU to extract spatial feature relationships, and then output the enhanced features f s :T×W f H f ×C f Perform spatial Average-pooling to obtain f′ s :T×C f ; For the features output by spatial modeling, the temporal feature modeling operation is used to extract the long-range temporal dependencies between video frames. The entire temporal feature modeling process is expressed as: the enhanced feature f′ s :T×C f , another GRU is used to model the timing of the video frames inside the video, and the output features are
[0102] After the spatiotemporal feature extraction module, the set matching metric module is used to flexibly match the videos. This module breaks through the constraints of time sequence and can be more flexible for some unaligned video instances.
[0103] Specifically, in this embodiment, a set matching method based on improved Hausdorff distance is adopted, and the expression formula of Hausdorff distance is:
[0104]
[0105]
[0106]
[0107] The Hausdorff distance measures the maximum mismatch between two sets. This measure is easily affected by noise, making the match inaccurate. The improved Hausdorff distance uses the average value of the corresponding relationship between multiple video frames to constrain it, making it less sensitive to noise:
[0108]
[0109] This distance only considers the relationship between the video to be tested and the template video, but does not fully consider the relationship between the template video and the video to be tested. Therefore, the following measurement operation is used:
[0110]
[0111] in, Represents the feature sequence of the template video in the video library, Represents the characteristics of the sample video to be tested; N i is the number of frames of one of the template videos; N q Represents the number of frames of the sample video to be tested; then the similarity loss constraint can be used to supervise network learning;
[0112] L sim =L ce (D,y)
[0113] Where D represents the predicted similarity of the video sample to be tested. If it matches, the similarity should be large; if it does not match, the similarity should be small. y represents which video class the video sample to be tested belongs to in the template video, and L ce is the cross entropy loss function;
[0114] At the same time, in order to make full use of the information of training samples, the true category constraint loss is used to make the data of the same category close to each other and the data of different categories far away from each other;
[0115]
[0116] N represents the number of all videos in each training batch, which is generally set to 40; L ce is the cross entropy loss function;
[0117] In summary, the loss function of the similarity measurement and the cross entropy loss function based on the true category, the overall loss function in the training process of the entire small sample behavior recognition network model is:
[0118] L=λL label +L sim
[0119] Among them, λ is the balance coefficient, which is used to balance the two loss functions and is generally set to 0.5;
[0120] (4) The video to be tested and the template video in the video library are input into the trained small sample behavior recognition network model to obtain the spatiotemporal enhancement features of the video to be tested and the spatiotemporal enhancement features of the template video in the video library. The set matching measurement module is used to calculate the similarity between the spatiotemporal enhancement features of the video to be tested and the spatiotemporal enhancement features of the template video in the video library to obtain the matching result of the video to be tested, and then the action category of the video to be tested is obtained from the matching result.
[0121] Figure 4 is a diagram of the video behavior recognition system architecture provided by an embodiment of the present invention, such as Figure 4 As shown, including:
[0122] The recognition network pre-training unit 410 is used to determine a pre-trained recognition network; the recognition network includes: a spatiotemporal feature extraction module and a set matching module; the spatiotemporal feature extraction module is used to extract the spatial features and temporal features of the received video, and the set matching module is used to match the received video with the template video based on the spatial features and temporal features and the spatiotemporal features of the template video to identify the behavior of the received video; the template video includes T categories of videos, and different categories of videos correspond to different behaviors, and the spatiotemporal features of each category of video in the template video are known; when training the recognition network, S categories of videos are randomly selected from the T categories of videos in a loop, K training samples are determined for each category of video, and the training samples corresponding to the S categories of videos are input into the recognition network for training, S is less than T, and K is less than a preset value;
[0123] The behavior recognition unit 420 is used to input the video to be recognized and the template video into the pre-trained recognition network to perform behavior recognition on the video to be recognized and output the corresponding behavior recognition result.
[0124] Understandably, Figure 4 The specific implementation of each unit can be found in the detailed description in the aforementioned method embodiment, which will not be repeated here.
[0125] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A video behavior recognition method, characterized in that: The steps include: Determine a pre-trained recognition network; the recognition network includes: a spatiotemporal feature extraction module and a set matching module; the spatiotemporal feature extraction module is used to extract the spatial features and temporal features of the received video, and the set matching module is used to match the received video with the template video based on the spatial features and temporal features and the spatiotemporal features of the template video to identify the behavior of the received video; the template video includes T categories of videos, and different categories of videos correspond to different behaviors, and the spatiotemporal features of each category of video in the template video are known; when training the recognition network, S categories of videos are randomly selected from the T categories of videos in a loop, K training samples are determined for each category of video, and the training samples corresponding to the S categories of videos are input into the recognition network for training, S is less than T, and K is less than a preset value; the overall loss function L of the recognition network is: L=λL label +L sim Among them, L label is the classification loss of the real labels of the video to be detected and the template video; L sim is the metric loss based on matching similarity; λ is the balance coefficient, which is used to balance the two loss functions; L sim =L ce (D,y) in, Represents the feature sequence of the template video in the video library, Represents the characteristics of the sample video to be tested; Representing video features To video features The Hausdorff distance of Representing video features To video features The Hausdorff distance of Video The ath feature in , that is, the feature corresponding to the ath frame of the video; Video The qth feature in the video is the feature corresponding to the qth frame of the video; N i is the number of frames of one of the template videos; N q represents the number of frames of the sample video to be tested; N represents the number of all videos in each training batch; L ce is the cross entropy loss function; and i They represent the behavior category predicted by the model and the real behavior category respectively; D represents the predicted similarity of the video sample to be tested; Representing video features To video features One-way modified Hausdorff distance; D b represents the bidirectional modified Hausdorff distance; The video to be identified and the template video are input into the pre-trained recognition network to perform behavior recognition on the video to be identified and output the corresponding behavior recognition result.
2. The method according to claim 1, characterized in that The spatiotemporal feature extraction module is used to extract the spatial features and temporal features of the received video, specifically including: the spatiotemporal feature extraction module extracts the feature sequence retained in the spatial dimension and temporal dimension of the received video; performs spatial feature modeling on the feature sequence, and obtains the spatial relationship within the video frame based on the gated recurrent unit and the features after spatial modeling as the spatial features of the received video; performs temporal feature modeling on the features after spatial modeling, and extracts the long-range temporal dependency between video frames based on the gated recurrent unit and the features after temporal modeling as the temporal features of the received video.
3. The method according to claim 1, characterized in that The set matching module is used to match the received video with the template video based on the spatial features and time features and the spatiotemporal features of the template video, specifically including: the set matching module models the spatial features and time features to obtain features with enhanced spatiotemporal relationships; based on the features with enhanced spatiotemporal relationships and the spatiotemporal features of the template video, using the correspondence between the videos to obtain the matching similarity between the received video and the template video; based on the matching similarity, determining which video in the received video and the template video is the most matched, and determining the behavior of the received video according to the behavior of the matched video.
4. A video behavior recognition system, characterized in that: include: A recognition network pre-training unit, used to determine a pre-trained recognition network; The recognition network includes: a spatiotemporal feature extraction module and a set matching module; the spatiotemporal feature extraction module is used to extract the spatial features and temporal features of the received video, and the set matching module is used to match the received video with the template video based on the spatial features and temporal features and the spatiotemporal features of the template video to identify the behavior of the received video; the template video includes T categories of videos, and different categories of videos correspond to different behaviors, and the spatiotemporal features of each category of video in the template video are known; when training the recognition network, S categories of videos are randomly selected from the T categories of videos in a loop, K training samples are determined for each category of video, and the training samples corresponding to the S categories of videos are input into the recognition network for training, S is less than T, and K is less than a preset value; the overall loss function L of the recognition network is: L=λL label +L sim Among them, L label is the classification loss of the real labels of the video to be detected and the template video; L sim is the metric loss based on matching similarity; λ is the balance coefficient, which is used to balance the two loss functions; L sim =L ce (D,y) in, Represents the feature sequence of the template video in the video library, Represents the characteristics of the sample video to be tested; Representing video features To video features The Hausdorff distance of Representing video features To video features The Hausdorff distance of Video The ath feature in , that is, the feature corresponding to the ath frame of the video; Video The qth feature in the video is the feature corresponding to the qth frame of the video; N i is the number of frames of one of the template videos; N q represents the number of frames of the sample video to be tested; N represents the number of all videos in each training batch; L ce is the cross entropy loss function; and i They represent the behavior category predicted by the model and the real behavior category respectively; D represents the predicted similarity of the video sample to be tested; Representing video features To video features One-way modified Hausdorff distance; D b represents the bidirectional modified Hausdorff distance; The behavior recognition unit is used to input the video to be recognized and the template video into the pre-trained recognition network to perform behavior recognition on the video to be recognized and output the corresponding behavior recognition result.
5. The system according to claim 4, characterized in that The spatiotemporal feature extraction module is used to extract the spatial features and temporal features of the received video, specifically including: the spatiotemporal feature extraction module extracts the feature sequence retained in the spatial dimension and temporal dimension of the received video; performs spatial feature modeling on the feature sequence, and obtains the spatial relationship within the video frame based on the gated recurrent unit and the features after spatial modeling as the spatial features of the received video; performs temporal feature modeling on the features after spatial modeling, and extracts the long-range temporal dependency between video frames based on the gated recurrent unit and the features after temporal modeling as the temporal features of the received video.
6. The system according to claim 4, characterized in that The set matching module is used to match the received video with the template video based on the spatial features and time features and the spatiotemporal features of the template video, specifically including: the set matching module models the spatial features and time features to obtain features with enhanced spatiotemporal relationships; based on the features with enhanced spatiotemporal relationships and the spatiotemporal features of the template video, using the correspondence between the videos to obtain the matching similarity between the received video and the template video; based on the matching similarity, determining which video in the received video and the template video is the most matched, and determining the behavior of the received video according to the behavior of the matched video.
