Video recognition method, device, readable medium and electronic device
By preprocessing the video to be processed and inputting a pre-trained recognition model, the problems of low video recognition efficiency and insufficient accuracy in the prior art are solved, and more efficient and accurate video recognition is achieved.
Patent Information
- Application Number
- CN202111052167.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-08
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2041-09-08
AI Technical Summary
The prior art requires a large amount of manpower and material resources to mark images in video recognition, which is inefficient and reduces the accuracy of video recognition.
A video recognition method is provided, by preprocessing the video to be processed, generating a target video, and inputting it into a pre-trained recognition model, including an encoder and a projection layer. The encoder uses a self-supervised method to pre-train with multiple pre-projection layers to extract the features of video frames, improving the characterization and generalization capabilities of the recognition model.
It improves the recognition accuracy of the video recognition model, reduces the dependence on image annotation, and improves the efficiency of video recognition.
Smart Images

Figure CN113723344B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technology, and in particular, to a video recognition method, device, readable medium and electronic device. Background Art
[0002] With the continuous development of image processing technology, more and more business fields have begun to use video recognition to complete tasks, such as using videos to identify dangerous behaviors, using videos to identify faces, using videos to identify road conditions, obstacles, etc. Usually, before performing video recognition, it is necessary to collect a large number of annotated images in advance as a reference for video recognition. However, image annotation requires a lot of manpower and material resources, the work is complicated, the efficiency is low, and it is difficult to achieve, which reduces the accuracy of video recognition. Summary of the invention
[0003] This summary is provided to introduce concepts in a brief form that will be described in detail in the detailed description below. This summary is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.
[0004] In a first aspect, the present disclosure provides a method for identifying a video, the method comprising:
[0005] Preprocessing the acquired video to be processed to obtain the target video;
[0006] Inputting the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, wherein the recognition result is used to characterize the category of the video to be processed; the recognition model includes an encoder and a projection layer;
[0007] The encoder is obtained by pre-training according to a plurality of pre-projection layers and a first number of pre-training videos, each of the pre-projection layers corresponds to a time sequence range, and the pre-projection layer is used to extract features of video frames within a corresponding time sequence range in the pre-training video;
[0008] The projection layer is trained based on the pre-trained encoder and a second number of training videos, where the second number is smaller than the first number, and the first sample video does not have a category label for indicating a category.
[0009] In a second aspect, the present disclosure provides a video recognition device, the device comprising:
[0010] A preprocessing module is used to preprocess the acquired video to be processed to obtain a target video;
[0011] A recognition module, used for inputting the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, wherein the recognition result is used to characterize the category of the video to be processed; the recognition model includes an encoder and a projection layer;
[0012] The encoder is obtained by pre-training according to a plurality of pre-projection layers and a first number of pre-training videos, each of the pre-projection layers corresponds to a time sequence range, and the pre-projection layer is used to extract features of video frames within a corresponding time sequence range in the pre-training video;
[0013] The projection layer is trained based on the pre-trained encoder and a second number of training videos, where the second number is smaller than the first number, and the first sample video does not have a category label for indicating a category.
[0014] In a third aspect, the present disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the method described in the first aspect of the present disclosure.
[0015] In a fourth aspect, the present disclosure provides an electronic device, including:
[0016] a storage device having a computer program stored thereon;
[0017] A processing device is used to execute the computer program in the storage device to implement the steps of the method described in the first aspect of the present disclosure.
[0018] Through the above technical solution, the present disclosure first pre-processes the acquired video to be processed to obtain the target video, and then inputs the target video into a pre-trained recognition model to obtain the recognition result output by the recognition model, which is used to characterize the category of the video to be processed. Among them, the recognition model includes an encoder and a projection layer, and the encoder is pre-trained according to multiple pre-projection layers and a first number of pre-training videos without category labels. Each pre-projection layer corresponds to a time range, which is used to extract the features of the video frames within the corresponding time range in the pre-training video. The recognition model is trained according to the pre-trained encoder and the second number of training videos. The encoder included in the recognition model in the present disclosure is pre-trained by a self-supervised method and with the help of a pre-projection layer that can extract the features of video frames within multiple time ranges, so as to improve the representation ability and generalization ability of the encoder, thereby improving the recognition accuracy of the recognition model.
[0019] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale. In the drawings:
[0021] Figure 1 is a flow chart of a video recognition method according to an exemplary embodiment;
[0022] Figure 2 is a flow chart of another video recognition method according to an exemplary embodiment;
[0023] Figure 3 is a flowchart of a pre-trained encoder according to an exemplary embodiment;
[0024] Figure 4 is a structural diagram of an encoder and a pre-projection layer according to an exemplary embodiment;
[0025] Figure 5 is a flowchart of another pre-trained encoder according to an exemplary embodiment;
[0026] Figure 6 is a flow chart showing a training recognition model according to an exemplary embodiment;
[0027] Figure 7 is a flowchart of another training recognition model according to an exemplary embodiment;
[0028] Figure 8 is a structural diagram of a recognition model according to an exemplary embodiment;
[0029] Fig. 9 is a flowchart of another training recognition model according to an exemplary embodiment;
[0030] Fig.10 is a block diagram of a video recognition device according to an exemplary embodiment;
[0031] Fig.11 is a block diagram of another video recognition device according to an exemplary embodiment;
[0032] Fig.12 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0033] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0034] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0035] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0036] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0037] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0038] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0039] Figure 1 is a flow chart of a video recognition method according to an exemplary embodiment. Figure 1 As shown, the method comprises the following steps:
[0040] Step 101, preprocessing the acquired video to be processed to obtain a target video.
[0041] For example, first, a video to be processed can be obtained. The video to be processed can be a video stored locally or a video obtained from a server through a network. Before the video to be processed is identified, the video to be processed needs to be preprocessed to obtain a preprocessed target video. Specifically, the preprocessing may include two steps: cleaning and sampling. Cleaning the video to be processed can be understood as performing noise reduction, cropping and other processing on the video to be processed, and video frames that are significantly different from adjacent video frames in the video to be processed can also be removed. Sampling the video to be processed can be done in one way by extracting multiple video frames from the video to be processed at a preset time interval to form a target video, and in another way by extracting a specified number of video frames from the video to be processed to form a target video. For example, the video to be processed can be cleaned first, and then 16 video frames can be extracted from the cleaned video, and the target video can be formed according to the time sequence of each video frame in the video to be processed, that is, the target video includes 16 video frames.
[0042] Step 102, input the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, and the recognition result is used to characterize the category of the video to be processed. The recognition model includes an encoder and a projection layer.
[0043] The encoder is pre-trained based on multiple pre-projection layers and a first number of pre-training videos, each pre-projection layer corresponds to a time range, and the pre-projection layer is used to extract features of video frames within the corresponding time range in the pre-training video.
[0044] The recognition model is trained based on a pre-trained encoder and a second number of training videos, where the second number is smaller than the first number, and the pre-training videos do not have category labels for indicating categories.
[0045] For example, a recognition model can be pre-trained to identify the category of the video, which can be an action category, a content category, a weather category, a security category, a face category, etc., which is not specifically limited in the present disclosure. The recognition model includes an encoder and a projection layer. The encoder is used to encode the video, and the projection layer is used to project the encoding result into a feature vector for characterizing the video, and finally the video is recognized based on the feature vector. After obtaining the target video, the target video can be input into the recognition model, and the output of the recognition model is the recognition result for characterizing the category of the video to be processed.
[0046] The encoder in the recognition model is pre-trained based on multiple pre-projection layers and a first number of pre-training videos without category labels. The recognition model is obtained by training the pre-trained encoder and the second number of training videos, wherein the second number is much smaller than the first number, for example, the second number is 100 and the first number is 5000. That is to say, before training the recognition model, a large number of pre-training videos without category labels and multiple pre-projection layers can be used to pre-train the encoder, wherein each pre-projection layer corresponds to a time range, which is used to extract the features of the video frames within the corresponding time range in the pre-training video, and each pre-projection layer corresponds to a different time range. The multiple time ranges corresponding to the multiple pre-projection layers are combined to form the complete time range of the pre-training video. That is to say, each pre-projection layer is used to extract the features of the video frames at different positions in the pre-training video. For example, the pre-training video includes 16 video frames, and there are two pre-projection layers. The time range corresponding to one pre-projection layer can be from frame 0 to frame 7, and the corresponding extracted features are from frame 0 to frame 7 in the pre-training video. The time range corresponding to another pre-projection layer may be the 8th frame to the 15th frame, and the corresponding features extracted are the 8th frame to the 15th frame in the pre-training video. For another example, the pre-training video includes 16 video frames, and there are four pre-projection layers. The time range corresponding to the first pre-projection layer may be the 0th frame to the 3rd frame, and the corresponding features extracted are the 0th frame to the 3rd frame in the pre-training video. The time range corresponding to the second pre-projection layer may be the 4th frame to the 7th frame, and the corresponding features extracted are the 4th frame to the 7th frame in the pre-training video. The time range corresponding to the third pre-projection layer may be the 8th frame to the 11th frame, and the corresponding features extracted are the 8th frame to the 11th frame in the pre-training video. The time range corresponding to the fourth pre-projection layer may be the 12th frame to the 15th frame, and the corresponding features extracted are the 12th frame to the 15th frame in the pre-training video.
[0047] When pre-training the encoder, any pre-training video can be shuffled in different orders to obtain two shuffled videos, and then the two shuffled videos are respectively input into the encoder, and the encoder encodes the two shuffled videos, and then the encoding results are respectively input into multiple pre-projection layers, and each pre-projection layer extracts the features of the video frames within the corresponding time range. Then, the self-supervised method (English: Self-supervised learning) is used to adjust the parameters in the encoder and multiple pre-projection layers by comparing the features of the video frames of the two shuffled videos within each time range, so as to achieve the purpose of pre-training the encoder. Since the features of the video frames within the time range corresponding to the multiple pre-projection layers are combined when pre-training the encoder, the encoder learns the representation of the video in time, which can effectively improve the representation ability and generalization ability of the encoder. At the same time, since videos without category labels are easy to obtain, a large number of videos in various fields can be selected as pre-training videos, which further improves the representation ability and generalization ability of the encoder.
[0048] After completing the pre-training of the encoder, the recognition model can be trained based on the pre-trained encoder and a second number of training videos, wherein the training videos can be a small number of videos with category labels. For example, any training video can be input into a pre-trained encoder for encoding, and then the encoding result can be input into a projection layer, which can project the encoding result into a feature vector that can characterize the training video, and then predict the category of the training video based on the feature vector. Finally, the predicted category of the training video can be compared with the category label of the training video to adjust the projection layer and / or the encoder, thereby achieving the purpose of training the recognition model. Since the pre-trained encoder has high representation and generalization capabilities, the recognition accuracy of the recognition model is also improved. At the same time, the recognition model can be quickly trained with a small number of training videos (which can be understood as fine-tuning the recognition model), which also improves the efficiency of the recognition model training.
[0049] In summary, the present disclosure first preprocesses the acquired video to be processed to obtain a target video, and then inputs the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, which is used to characterize the category of the video to be processed. Among them, the recognition model includes an encoder and a projection layer, and the encoder is pre-trained according to multiple pre-projection layers and a first number of pre-training videos without category labels, and each pre-projection layer corresponds to a time range, which is used to extract the features of the video frames within the corresponding time range in the pre-training video. The recognition model is trained according to the pre-trained encoder and the second number of training videos. The encoder included in the recognition model in the present disclosure is pre-trained by a self-supervised method and with the help of a pre-projection layer that can extract the features of video frames within multiple time ranges, so as to improve the representation ability and generalization ability of the encoder, thereby improving the recognition accuracy of the recognition model.
[0050] Figure 2 is a flowchart of another video recognition method according to an exemplary embodiment. Figure 2 As shown, the implementation of step 102 may include:
[0051] Step 1021, encode the target video through an encoder to obtain a coding vector corresponding to the target video.
[0052] Step 1022, projecting the coding vector into a video vector through a projection layer, the dimension of the video vector is the same as the number of categories to be selected, and the category of the video to be processed belongs to the category to be selected.
[0053] Step 1023, determining the recognition result according to the video vector.
[0054] For example, in the specific process of identifying the target video, the target video can be first input into the encoder, and the encoder encodes the target video, and the encoder outputs the encoding vector corresponding to the target video. After that, the encoding vector is input into the projection layer, and the projection layer projects the encoding vector into a video vector (i.e., the output of the projection layer) used to characterize the target video. The projection layer can be understood as a linear layer or a fully connected layer. Among them, the dimension of the video vector (which can also be understood as the output dimension of the projection layer) is the same as the number of categories to be selected. The categories to be selected can be understood as the number of categories that the video to be processed may be identified as, which can be determined according to specific needs. For example, if the video to be processed is a road condition video collected by a vehicle, which is used to determine the slope of the road, then the categories to be selected can be: smooth road condition, uphill road condition, downhill road condition, a total of 3 types. For another example, if the video to be processed is a surveillance video collected by a security system, which is used to determine whether there is a dangerous situation, then the categories to be selected can be: safe, third-level dangerous, second-level dangerous, first-level dangerous, a total of 4 types.
[0055] After obtaining the video vector output by the projection layer, the Softmax layer can be used to process the video vector to obtain the matching probability between the target video and multiple candidate categories. Finally, the candidate category with the highest matching probability can be used as the category of the video to be processed, that is, the recognition result.
[0056] Figure 3 is a flowchart of a pre-trained encoder according to an exemplary embodiment. Figure 3 As shown, the encoder is pre-trained as follows:
[0057] Step 201 : preprocess a first number of pre-training videos to obtain a target pre-training video corresponding to each pre-training video.
[0058] Step 202: randomly generate two adjustment sequences, and for each target pre-training video, adjust the target pre-training video according to the two adjustment sequences to obtain a first video and a second video corresponding to the target pre-training video.
[0059] Step 203, input the first video into an encoder, and input the output of the encoder into multiple pre-projection layers to obtain features of video frames within a time range corresponding to the pre-projection layer in the first video extracted by each pre-projection layer.
[0060] Step 204, input the second video into an encoder, and input the output of the encoder into a plurality of pre-projection layers to obtain features of video frames within a time range corresponding to the pre-projection layer in the second video extracted by each pre-projection layer.
[0061] Step 205 , pre-training an encoder and a plurality of pre-projection layers according to features of video frames within a plurality of time ranges in the first video and features of video frames within a plurality of time ranges in the second video.
[0062] For example, when pre-training the encoder, a first number of pre-training videos without category labels can be collected in advance, and then each pre-training video can be pre-processed to obtain a target pre-training video corresponding to each pre-training video, that is, to obtain a first number of target pre-training videos. The pre-processing method of the pre-training video can be the same as the pre-processing method of the to-be-processed video in step 101, which will not be repeated here. Afterwards, multiple pre-projection layers can be established, and the input end of each pre-projection layer can be connected to the output end of the encoder, such as Figure 4 As shown. The pre-projection layer can be understood as a linear layer or a fully connected layer. The input dimension of each pre-projection layer is the output dimension of the encoder. The output dimension of each pre-projection layer can be the same or different, and this disclosure does not specifically limit this.
[0063] Afterwards, two different adjustment orders can be randomly generated, and for any target pre-training video, adjustments can be made according to the two adjustment orders to obtain the first video and the second video corresponding to the target pre-training video. For example, the target pre-training video includes 16 video frames, and there are two pre-projection layers. The timing range corresponding to one pre-projection layer may be the 0th frame to the 7th frame, and the timing range corresponding to the other pre-projection layer may be the 8th frame to the 15th frame. One adjustment order may be: from the 0th frame to the 15th frame (i.e., the original order), and another adjustment order may be from the 8th frame to the 15th frame, and then from the 0th frame to the 7th frame (i.e., the second half of the target pre-training video is exchanged with the first half). Then the first video is from the 0th frame to the 15th frame, and the second video is from the 8th frame to the 15th frame, and then from the 0th frame to the 7th frame.
[0064] For another example, there are four pre-projection layers, and the timing range corresponding to the first pre-projection layer may be from frame 0 to frame 3, the timing range corresponding to the second pre-projection layer may be from frame 4 to frame 7, the timing range corresponding to the third pre-projection layer may be from frame 8 to frame 11, and the timing range corresponding to the fourth pre-projection layer may be from frame 12 to frame 15. One adjustment order may be from frame 0 to frame 15 (i.e., the original order), and another adjustment order may be from frame 4 to frame 7, then from frame 0 to frame 3, then from frame 12 to frame 15, and then from frame 8 to frame 11. Then the first video is from frame 0 to frame 15, and the second video is from frame 4 to frame 7, then from frame 0 to frame 3, then from frame 12 to frame 15, and then from frame 8 to frame 11.
[0065] The first video and the second video can be input into the encoder respectively, and the output of the encoder can be input into multiple pre-projection layers to obtain the features of the video frames in the time range corresponding to the pre-projection layer in the first video and the features of the video frames in the time range corresponding to the pre-projection layer in the second video extracted by each pre-projection layer. Finally, the encoder and multiple pre-projection layers are pre-trained according to the features of the video frames in multiple time ranges in the first video and the features of the video frames in multiple time ranges in the second video. For example, the loss function can be determined by a self-supervised method, and the parameters of the neurons in the encoder and multiple pre-projection layers can be corrected by a back-propagation algorithm with the goal of reducing the loss function. The parameters of the neurons can be, for example, the weights (English: Weight) and biases (English: Bias) of the neurons. Repeat the above steps until the loss function meets the preset conditions, for example, the loss function is less than the preset loss threshold, and the pre-training of the encoder is completed.
[0066] Figure 5 is a flowchart of another pre-trained encoder according to an exemplary embodiment. Figure 5 As shown, step 205 can be implemented by the following steps:
[0067] Step 2051, for each time sequence range, determine the positive similarity and negative similarity of the time sequence range according to the two adjustment orders, the positive similarity being the similarity between the features of the video frames in the time sequence range in the first video and the features of the video frames in the target time sequence range in the second video. In the two adjustment orders, the time sequence range corresponds to the target time sequence range.
[0068] Step 2052, determining the loss corresponding to the time series range according to the positive similarity and negative similarity of the time series range; the loss corresponding to the time series range is negatively correlated with the positive similarity of the time series range, and positively correlated with the negative similarity of the time series range.
[0069] Step 2053, determining the comprehensive loss according to the loss corresponding to each time series range.
[0070] Step 2054, with the goal of reducing the comprehensive loss, use the back-propagation algorithm to pre-train the encoder and multiple pre-projection layers.
[0071] For example, a specific method for pre-training an encoder and multiple pre-projection layers is to first determine the loss corresponding to each time series range, and then determine the comprehensive loss based on the loss corresponding to each time series range. For example, the losses corresponding to each time series range can be averaged or weighted summed as the comprehensive loss. Finally, with the goal of reducing the comprehensive loss, the encoder and multiple pre-projection layers are pre-trained using the back propagation algorithm. Specifically, the loss corresponding to each time series range can be determined based on the positive similarity and negative similarity of the time series range, and the loss corresponding to the time series range is negatively correlated with the positive similarity of the time series range, and positively correlated with the negative similarity of the time series range.
[0072] Among them, the positive similarity can be understood as the similarity between the features of the video frames within the time range in the first video and the features of the video frames within the target time range in the second video. The negative similarity includes two categories: one is the similarity between the features of the video frames within the time range in the first video and the features of the video frames within other time ranges except the time range in the first video; the other is the similarity between the features of the video frames within the time range in the first video and the features of the video frames within other time ranges except the target time range in the second video.
[0073] It should be noted that the target timing range is the timing range corresponding to the timing range in the two adjustment orders. For example, the first video is from frame 0 to frame 15, and the second video is from frame 8 to frame 15, and then from frame 0 to frame 7. Then frame 0 to frame 7 in the first video corresponds to frame 8 to frame 15 in the second video (i.e. frame 0 to frame 7 in the target pre-trained video), and frame 8 to frame 15 in the first video corresponds to frame 0 to frame 7 in the second video (i.e. frame 8 to frame 15 in the target pre-trained video).
[0074] For another example, the first video is from frame 0 to frame 15, and the second video is from frame 4 to frame 7, then from frame 0 to frame 3, then from frame 12 to frame 15, and then from frame 8 to frame 11. Then frame 0 to frame 3 in the first video corresponds to frame 4 to frame 7 in the second video (i.e., frame 0 to frame 3 in the target pre-training video), frame 12 to frame 15 in the first video corresponds to frame 8 to frame 11 in the second video (i.e., frame 12 to frame 15 in the target pre-training video), and so on.
[0075] In one implementation, the loss corresponding to the timing range may be determined by Formula 1:
[0076]
[0077] Among them, L i represents the loss corresponding to the i-th time series range, and M represents the number of pre-projection layers (the number of time series ranges). i represents the features of the video frame in the i-th time range in the first video, q i+ represents the features of the video frames in the target time range corresponding to the i-th time range in the second video, p j represents the features of the video frame within the jth time range in the first video, q k represents the features of the video frames in the kth time range in the second video. sim represents the similarity, sim(p i ,q i+ ) represents the positive similarity of the i-th time series range, sim(p i ,p j ) and sim(p i ,q k ) represents the two negative similarities of the i-th time series range, namely, sim(p i ,p j ) represents the similarity between the features of the video frame in the i-th time range in the first video and the features of the video frames in other time ranges in the first video except the i-th time range, sim(p i ,q k) represents the similarity between the features of the video frames within the i-th time range in the first video and the features of the video frames within other time ranges in the second video except the target time range corresponding to the i-th time range.
[0078] Figure 6 is a flowchart of a training recognition model according to an exemplary embodiment. Figure 6 As shown, the recognition model is trained in the following way:
[0079] Step 301 : pre-process a second number of training videos to obtain a target training video corresponding to each training video.
[0080] Step 302: input each target training video into the recognition model, and train the recognition model according to the output of the recognition model and the category label of the training video corresponding to the target training video.
[0081] For example, when training the recognition model, a second number of training videos can be collected in advance, and each training video has a category label. Then, each training video is preprocessed to obtain a target training video corresponding to each training video, that is, a second number of target training videos are obtained. Among them, the method of preprocessing the training video can be the same as the method of preprocessing the video to be processed in step 101, which will not be repeated here. Afterwards, each target training video can be input into the recognition model, and the recognition model can be trained according to the output of the recognition model and the category label of the training video corresponding to the target training video. For example, the loss function can be determined according to the output of the recognition model and the category label of the training video corresponding to the target training video, and with the goal of reducing the loss function, the back propagation algorithm is used to correct the parameters of the neurons in the recognition model. The parameters of the neurons can be, for example, the weights and biases of the neurons. Repeat the above steps until the loss function meets the preset conditions, such as the loss function is less than the preset loss threshold, and the training of the recognition model is completed.
[0082] Figure 7 is a flowchart of another training recognition model according to an exemplary embodiment. Figure 7 As shown, step 302 may include:
[0083] Step 3021, input the target training video into a pre-trained encoder to obtain a training coding vector corresponding to the target training video output by the pre-trained encoder.
[0084] Step 3022, input the training coding vector into the projection layer to obtain the training video vector output by the projection layer.
[0085] Step 3023, input the training video vector into the classification layer of the recognition model to obtain the training recognition result output by the classification layer, and use the training recognition result as the output of the recognition model.
[0086] Step 3024: train the projection layer and / or encoder according to the training recognition result and the category label of the training video corresponding to the target training video.
[0087] For example, the structure of the recognition model can be as follows Figure 8 As shown, it includes a pre-trained encoder, a projection layer and a classification layer, wherein the projection layer can be understood as a linear layer or a fully connected layer. The input dimension of the projection layer is the output dimension of the encoder, and the output dimension of the projection layer can be determined according to the number of categories that the video to be processed may be identified as. The classification layer can be understood as a Softmax layer. The specific method of training the recognition model is to first input any target training video into the pre-trained encoder to obtain the training encoding vector corresponding to the target training video output by the pre-trained encoder. After that, the training encoding vector is input into the projection layer to obtain the training video vector output by the projection layer, and finally, the training video vector is input into the classification layer of the recognition model to obtain the training recognition result output by the classification layer, and the training recognition result is used as the output of the recognition model. Specifically, the classification layer can determine the matching probability of the target training video with multiple candidate categories according to the training video vector, and then use the candidate category with the highest matching probability as the recognition result. Finally, the projection layer and / or the encoder can be trained according to the training recognition result and the category label of the training video corresponding to the target training video. For example, the matching probability of the target training video determined by the classification layer and a plurality of selected categories can be compared with the category label of the training video corresponding to the target training video to correct the parameters of the neurons in the projection layer and / or the encoder. The parameters of the neurons can be, for example, the weights and biases of the neurons. It should be noted that, in one embodiment, when training the recognition model, only the parameters of the neurons in the projection layer can be corrected, so that after a small amount of adjustment (which can also be understood as fine-tuning), the trained recognition model can be quickly obtained. In another implementation, when training the recognition model, the parameters of the neurons in the projection layer and the encoder can also be corrected at the same time, which can further improve the recognition accuracy of the recognition model. In yet another implementation, when training the recognition model, only the parameters of the neurons in the encoder can also be corrected. The present disclosure does not specifically limit this.
[0088] Fig. 9 is a flowchart of another training recognition model according to an exemplary embodiment. Fig. 9 As shown, the recognition model is also trained in the following way:
[0089] Step 303, according to the number of categories to be selected, determine the output dimension of the projection layer so that the dimension of the training video vector output by the projection layer is the same as the number of categories to be selected. The category of the video to be processed belongs to the category to be selected.
[0090] For example, when training the recognition model, the output dimension of the projection layer can be determined according to the number of candidate categories that the video to be processed may be identified as, so that the dimension of the training video vector output by the projection layer is the same as the number of candidate categories. In other words, the output dimension of the projection layer can be determined according to the specific tasks that the recognition model needs to complete. For example, the video to be processed is a road condition video collected by a vehicle, which is used to determine the slope of the road. The candidate categories can be: smooth road conditions, uphill road conditions, downhill road conditions, a total of 3 types. Then the output dimension of the projection layer can be 3. For another example, the video to be processed is a surveillance video collected by a security system, which is used to determine whether there is a dangerous situation. The candidate categories can be: safety, third-level danger, second-level danger, and first-level danger, a total of 4 types. Then the output dimension of the projection layer can be 4. In this way, after pre-training the encoder with a large number of pre-training videos without category labels, when training the recognition model, projection layers with different output dimensions can be selected according to specific needs, and a recognition model that can recognize multiple candidate categories can be trained using a small amount of training videos.
[0091] In summary, the present disclosure first preprocesses the acquired video to be processed to obtain a target video, and then inputs the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, which is used to characterize the category of the video to be processed. Among them, the recognition model includes an encoder and a projection layer, and the encoder is pre-trained according to multiple pre-projection layers and a first number of pre-training videos without category labels, and each pre-projection layer corresponds to a time range, which is used to extract the features of the video frames within the corresponding time range in the pre-training video. The recognition model is trained according to the pre-trained encoder and the second number of training videos. The encoder included in the recognition model in the present disclosure is pre-trained by a self-supervised method and with the help of a pre-projection layer that can extract the features of video frames within multiple time ranges, so as to improve the representation ability and generalization ability of the encoder, thereby improving the recognition accuracy of the recognition model.
[0092] Fig.10 is a block diagram of a video recognition device according to an exemplary embodiment. Fig.10 As shown, the device 400 includes:
[0093] The preprocessing module 401 is used to preprocess the acquired video to be processed to obtain a target video.
[0094] The recognition module 402 is used to input the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, and the recognition result is used to characterize the category of the video to be processed. The recognition model includes an encoder and a projection layer.
[0095] The encoder is pre-trained based on multiple pre-projection layers and a first number of pre-training videos, each pre-projection layer corresponds to a time range, and the pre-projection layer is used to extract features of video frames within the corresponding time range in the pre-training video.
[0096] The recognition model is trained based on a pre-trained encoder and a second number of training videos, where the second number is smaller than the first number, and the pre-training videos do not have category labels for indicating categories.
[0097] Fig.11 is a block diagram of another video recognition device according to an exemplary embodiment. Fig.11 As shown, the identification module 402 may include:
[0098] The encoding submodule 4021 is used to encode the target video through an encoder to obtain a coding vector corresponding to the target video.
[0099] The projection submodule 4022 is used to project the coding vector into a video vector through a projection layer. The dimension of the video vector is the same as the number of categories to be selected, and the category of the video to be processed belongs to the category to be selected.
[0100] The recognition submodule 4023 is used to determine the recognition result according to the video vector.
[0101] In one implementation, the encoder may be pre-trained in the following manner:
[0102] Step A: preprocessing a first number of pre-training videos to obtain a target pre-training video corresponding to each pre-training video.
[0103] Step B: randomly generate two adjustment sequences, and for each target pre-training video, adjust the target pre-training video according to the two adjustment sequences to obtain a first video and a second video corresponding to the target pre-training video.
[0104] Step C: input the first video into an encoder, and input the output of the encoder into multiple pre-projection layers to obtain features of video frames within a time range corresponding to the pre-projection layer in the first video extracted by each pre-projection layer.
[0105] Step D: input the second video into an encoder, and input the output of the encoder into multiple pre-projection layers to obtain features of video frames in the time range corresponding to the pre-projection layer in the second video extracted by each pre-projection layer.
[0106] Step E: pre-training an encoder and multiple pre-projection layers based on features of video frames within multiple time ranges in the first video and features of video frames within multiple time ranges in the second video.
[0107] In another implementation, step E may be implemented by the following steps:
[0108] Step E1, for each time sequence range, determine the positive similarity and negative similarity of the time sequence range according to two adjustment orders, the positive similarity being the similarity between the features of the video frames within the time sequence range in the first video and the features of the video frames within the target time sequence range in the second video. In the two adjustment orders, the time sequence range corresponds to the target time sequence range.
[0109] Step E2, determining the loss corresponding to the time series range according to the positive similarity and negative similarity of the time series range; the loss corresponding to the time series range is negatively correlated with the positive similarity of the time series range, and positively correlated with the negative similarity of the time series range.
[0110] Step E3, determining the comprehensive loss according to the loss corresponding to each time series range.
[0111] In step E4, the encoder and multiple pre-projection layers are pre-trained using the back-propagation algorithm with the goal of reducing the comprehensive loss.
[0112] In another implementation, the recognition model may be obtained by training in the following manner:
[0113] Step F: preprocessing the second number of training videos to obtain a target training video corresponding to each training video.
[0114] Step G, input each target training video into the recognition model, and train the recognition model according to the output of the recognition model and the category label of the training video corresponding to the target training video.
[0115] In yet another implementation, step G may include:
[0116] Step G1, inputting the target training video into a pre-trained encoder to obtain a training coding vector corresponding to the target training video output by the pre-trained encoder.
[0117] Step G2, input the training coding vector into the projection layer to obtain the training video vector output by the projection layer.
[0118] Step G3, input the training video vector into the classification layer of the recognition model to obtain the training recognition result output by the classification layer, and use the training recognition result as the output of the recognition model.
[0119] Step G4, training the projection layer and / or the encoder according to the training recognition result and the category label of the training video corresponding to the target training video.
[0120] In yet another implementation, the recognition model is also trained in the following manner:
[0121] Step H: Determine the output dimension of the projection layer according to the number of the categories to be selected, so that the dimension of the training video vector output by the projection layer is the same as the number of the categories to be selected. The category of the video to be processed belongs to the category to be selected.
[0122] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0123] In summary, the present disclosure first preprocesses the acquired video to be processed to obtain a target video, and then inputs the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, which is used to characterize the category of the video to be processed. Among them, the recognition model includes an encoder and a projection layer, and the encoder is pre-trained according to multiple pre-projection layers and a first number of pre-training videos without category labels, and each pre-projection layer corresponds to a time range, which is used to extract the features of the video frames within the corresponding time range in the pre-training video. The recognition model is trained according to the pre-trained encoder and the second number of training videos. The encoder included in the recognition model in the present disclosure is pre-trained by a self-supervised method and with the help of a pre-projection layer that can extract the features of video frames within multiple time ranges, so as to improve the representation ability and generalization ability of the encoder, thereby improving the recognition accuracy of the recognition model.
[0124] Reference below Fig.12 , which shows a schematic diagram of the structure of an electronic device (i.e., the execution subject of the above-mentioned video recognition method, which can be a terminal device or a server) 500 suitable for implementing the embodiment of the present disclosure. The terminal device in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.12 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0125] like Fig.12As shown, the electronic device 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0126] Typically, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Fig.12 The electronic device 500 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0127] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0128] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0129] In some embodiments, the terminal devices and servers may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0130] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0131] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: pre-processes the acquired video to be processed to obtain a target video; inputs the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, and the recognition result is used to characterize the category of the video to be processed; the recognition model includes an encoder and a projection layer; the encoder is pre-trained based on multiple pre-projection layers and a first number of pre-training videos, each of the pre-projection layers corresponds to a time range, and the pre-projection layer is used to extract features of video frames within the corresponding time range in the pre-training video; the projection layer is trained based on the pre-trained encoder and a second number of training videos, the second number is less than the first number, and the first sample video does not have a category label for indicating a category.
[0132] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0133] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0134] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a module does not limit the module itself in some cases. For example, a preprocessing module may also be described as a "module for preprocessing a video to be processed."
[0135] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0136] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0137] According to one or more embodiments of the present disclosure, Example 1 provides a video recognition method, comprising: preprocessing the acquired video to be processed to obtain a target video; inputting the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, wherein the recognition result is used to characterize the category of the video to be processed; the recognition model comprises an encoder and a projection layer; the encoder is pre-trained based on multiple pre-projection layers and a first number of pre-training videos, each of the pre-projection layers corresponds to a time range, and the pre-projection layer is used to extract features of video frames within the corresponding time range in the pre-training video; the projection layer is trained based on the pre-trained encoder and a second number of training videos, the second number is smaller than the first number, and the first sample video does not have a category label for indicating a category.
[0138] According to one or more embodiments of the present disclosure, Example 2 provides the method of Example 1, wherein the target video is input into a pre-trained recognition model to obtain a recognition result output by the recognition model, including: encoding the target video through the encoder to obtain a coding vector corresponding to the target video; projecting the coding vector into a video vector through the projection layer, the dimension of the video vector being the same as the number of categories to be selected, and the category of the video to be processed belongs to the category to be selected; and determining the recognition result based on the video vector.
[0139] According to one or more embodiments of the present disclosure, Example 3 provides the method of Example 1, wherein the encoder is pre-trained in the following manner: pre-processing a first number of the pre-training videos to obtain a target pre-training video corresponding to each of the pre-training videos; randomly generating two adjustment orders, and for each of the target pre-training videos, adjusting the target pre-training video according to the two adjustment orders to obtain a first video and a second video corresponding to the target pre-training video; inputting the first video into the encoder, and inputting the output of the encoder into a plurality of the pre-projection layers to obtain features of video frames within a time range corresponding to the pre-projection layer in the first video extracted by each of the pre-projection layers; inputting the second video into the encoder, and inputting the output of the encoder into a plurality of the pre-projection layers to obtain features of video frames within a time range corresponding to the pre-projection layer in the second video extracted by each of the pre-projection layers; pre-training the encoder and the plurality of the pre-projection layers according to features of the video frames within a plurality of time ranges in the first video and features of the video frames within a plurality of time ranges in the second video.
[0140] According to one or more embodiments of the present disclosure, Example 4 provides the method of Example 3, wherein the encoder and the multiple pre-projection layers are pre-trained according to the features of the video frames within multiple time ranges in the first video and the features of the video frames within multiple time ranges in the second video, including: for each time range, the positive similarity and the negative similarity of the time range are determined according to the two adjustment orders, the positive similarity being the similarity between the features of the video frames within the time range in the first video and the features of the video frames within the target time range in the second video; in the two adjustment orders, the time range corresponds to the target time range; according to the positive similarity and the negative similarity of the time range, the loss corresponding to the time range is determined; the loss corresponding to the time range is negatively correlated with the positive similarity of the time range, and positively correlated with the negative similarity of the time range; the comprehensive loss is determined according to the loss corresponding to each time range; with the goal of reducing the comprehensive loss, the encoder and the multiple pre-projection layers are pre-trained using a back propagation algorithm.
[0141] According to one or more embodiments of the present disclosure, Example 5 provides the method of Example 1, wherein the recognition model is obtained by training in the following manner: preprocessing a second number of the training videos to obtain a target training video corresponding to each of the training videos; inputting each of the target training videos into the recognition model, and training the recognition model based on the output of the recognition model and the category label of the training video corresponding to the target training video.
[0142] According to one or more embodiments of the present disclosure, Example 6 provides the method of Example 5, wherein each of the target training videos is input into the recognition model, and the recognition model is trained according to the output of the recognition model and the category label of the training video corresponding to the target training video, including: inputting the target training video into the pre-trained encoder to obtain a training coding vector corresponding to the target training video output by the pre-trained encoder; inputting the training coding vector into the projection layer to obtain a training video vector output by the projection layer; inputting the training video vector into the classification layer of the recognition model to obtain a training recognition result output by the classification layer, and using the training recognition result as the output of the recognition model; training the projection layer, and / or the encoder according to the training recognition result and the category label of the training video corresponding to the target training video.
[0143] According to one or more embodiments of the present disclosure, Example 7 provides the method of Example 6, and the recognition model is also trained in the following manner: according to the number of categories to be selected, the output dimension of the projection layer is determined so that the dimension of the training video vector output by the projection layer is the same as the number of categories to be selected; the category of the video to be processed belongs to the category to be selected.
[0144] According to one or more embodiments of the present disclosure, Example 8 provides a video recognition device, comprising: a preprocessing module, used to preprocess the acquired video to be processed to obtain a target video; a recognition module, used to input the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, and the recognition result is used to characterize the category of the video to be processed; the recognition model includes an encoder and a projection layer; the encoder is pre-trained according to multiple pre-projection layers and a first number of pre-training videos, each of the pre-projection layers corresponds to a time range, and the pre-projection layer is used to extract features of video frames within the corresponding time range in the pre-training video; the projection layer is trained according to the pre-trained encoder and a second number of training videos, the second number is smaller than the first number, and the first sample video does not have a category label for indicating a category.
[0145] According to one or more embodiments of the present disclosure, Example 9 provides a computer-readable medium having a computer program stored thereon, which implements the steps of the methods described in Examples 1 to 7 when executed by a processing device.
[0146] According to one or more embodiments of the present disclosure, Example 10 provides an electronic device, comprising: a storage device on which a computer program is stored; and a processing device for executing the computer program in the storage device to implement the steps of the method described in Examples 1 to 7.
[0147] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0148] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0149] Although the subject matter has been described in language specific to structural features and / or method logic actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims. Regarding the device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Claims
1. A video recognition method, characterized in that: The method comprises: Preprocessing the acquired video to be processed to obtain the target video; Inputting the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, wherein the recognition result is used to characterize the category of the video to be processed; the recognition model includes an encoder and a projection layer; The encoder is obtained by pre-training according to a plurality of pre-projection layers and a first number of pre-training videos, each of the pre-projection layers corresponds to a time sequence range, and the pre-training videos include a first video and a second video with different adjustment orders; the pre-projection layer is used to extract features of video frames within a corresponding time sequence range in the pre-training videos; The recognition model is trained based on the pre-trained encoder and a second number of training videos, the second number is smaller than the first number, and the pre-training videos do not have category labels for indicating categories; The encoder is pre-trained in the following way: Preprocessing the first number of the pre-training videos to obtain a target pre-training video corresponding to each of the pre-training videos; Randomly generate two adjustment orders, and for each of the target pre-training videos, adjust the target pre-training video according to the two adjustment orders to obtain a first video and a second video corresponding to the target pre-training video; Input the first video into the encoder, and input the output of the encoder into the plurality of pre-projection layers to obtain features of video frames within a time range corresponding to the pre-projection layer in the first video extracted by each pre-projection layer; Input the second video into the encoder, and input the output of the encoder into the plurality of pre-projection layers to obtain features of video frames within a time range corresponding to the pre-projection layer in the second video extracted by each pre-projection layer; Pre-training the encoder and the plurality of pre-projection layers according to features of video frames within a plurality of time ranges in the first video and features of video frames within a plurality of time ranges in the second video; The pre-training of the encoder and the plurality of pre-projection layers according to features of video frames within a plurality of time ranges in the first video and features of video frames within a plurality of time ranges in the second video comprises: For each time sequence range, the positive similarity and negative similarity of the time sequence range are determined according to the two adjustment orders, wherein the positive similarity is the similarity between the features of the video frames within the time sequence range in the first video and the features of the video frames within the target time sequence range in the second video; in the two adjustment orders, the time sequence range corresponds to the target time sequence range; the negative similarity includes: the similarity between the features of the video frames within the time sequence range in the first video and the features of the video frames within other time sequence ranges in the first video except the time sequence range; and the similarity between the features of the video frames within the time sequence range in the first video and the features of the video frames within other time sequence ranges in the second video except the target time sequence range; Determine the loss corresponding to the time series range according to the positive similarity and the negative similarity of the time series range; the loss corresponding to the time series range is negatively correlated with the positive similarity of the time series range, and positively correlated with the negative similarity of the time series range; Determine the comprehensive loss based on the losses corresponding to each time series range; With the goal of reducing the comprehensive loss, the encoder and the plurality of pre-projection layers are pre-trained using a back-propagation algorithm.
2. The method according to claim 1, characterized in that The step of inputting the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model includes: Encoding the target video by the encoder to obtain a coding vector corresponding to the target video; Projecting the coding vector into a video vector through the projection layer, the dimension of the video vector is the same as the number of categories to be selected, and the category of the video to be processed belongs to the category to be selected; The recognition result is determined according to the video vector.
3. The method according to claim 1, characterized in that The recognition model is obtained by training in the following way: Preprocessing the second number of the training videos to obtain a target training video corresponding to each of the training videos; Each of the target training videos is input into the recognition model, and the recognition model is trained according to the output of the recognition model and the category label of the training video corresponding to the target training video.
4. The method according to claim 3, characterized in that Inputting each of the target training videos into the recognition model, and training the recognition model according to the category label of the training video corresponding to the target training video output by the recognition model, comprises: Inputting the target training video into the pre-trained encoder to obtain a training coding vector corresponding to the target training video output by the pre-trained encoder; Inputting the training coding vector into the projection layer to obtain a training video vector output by the projection layer; Input the training video vector into the classification layer of the recognition model to obtain a training recognition result output by the classification layer, and use the training recognition result as the output of the recognition model; The projection layer and / or the encoder are trained according to the training recognition result and the category label of the training video corresponding to the target training video.
5. The method according to claim 4, characterized in that The recognition model is also trained in the following way: According to the number of categories to be selected, the output dimension of the projection layer is determined so that the dimension of the training video vector output by the projection layer is the same as the number of categories to be selected; the category of the video to be processed belongs to the category to be selected.
6. A video recognition device, characterized in that: The device comprises: A preprocessing module is used to preprocess the acquired video to be processed to obtain a target video; A recognition module, used for inputting the target video into a pre-trained recognition model to obtain a recognition result output by the recognition model, wherein the recognition result is used to characterize the category of the video to be processed; the recognition model includes an encoder and a projection layer; The encoder is obtained by pre-training according to a plurality of pre-projection layers and a first number of pre-training videos, each of the pre-projection layers corresponds to a time sequence range, and the pre-training videos include a first video and a second video with different adjustment orders; the pre-projection layer is used to extract features of video frames within a corresponding time sequence range in the pre-training videos; The recognition model is trained based on the pre-trained encoder and a second number of training videos, the second number is smaller than the first number, and the pre-training videos do not have category labels for indicating categories; The encoder is obtained by pre-training in the following manner: pre-processing a first number of the pre-training videos to obtain a target pre-training video corresponding to each of the pre-training videos; randomly generating two adjustment orders, and adjusting the target pre-training video according to the two adjustment orders for each of the target pre-training videos to obtain a first video and a second video corresponding to the target pre-training video; inputting the first video into the encoder, and inputting the output of the encoder into a plurality of pre-projection layers to obtain features of video frames within a time range corresponding to the pre-projection layer in the first video extracted by each of the pre-projection layers; inputting the second video into the encoder, and inputting the output of the encoder into a plurality of pre-projection layers to obtain features of video frames within a time range corresponding to the pre-projection layer in the second video extracted by each of the pre-projection layers; pre-training the encoder and the plurality of pre-projection layers according to features of video frames within a plurality of time ranges in the first video and features of video frames within a plurality of time ranges in the second video; , pre-training the encoder and the plurality of pre-projection layers, including: for each time range, determining the positive similarity and negative similarity of the time range according to the two adjustment orders, the positive similarity being the similarity between the features of the video frames in the time range in the first video and the features of the video frames in the target time range in the second video; in the two adjustment orders, the time range corresponds to the target time range; the negative similarity includes: the features of the video frames in the time range in the first video and the features of the video frames in other time ranges in the first video except the time range similarity; and the similarity between the features of the video frames within the time range in the first video and the features of the video frames within other time ranges except the target time range in the second video; according to the positive similarity and the negative similarity of the time range, determine the loss corresponding to the time range; the loss corresponding to the time range is negatively correlated with the positive similarity of the time range, and positively correlated with the negative similarity of the time range; determine the comprehensive loss according to the loss corresponding to each time range; with the goal of reducing the comprehensive loss, use the back propagation algorithm to pre-train the encoder and the multiple pre-projection layers.
7. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processing device, the steps of the method described in any one of claims 1 to 5 are implemented.
8. An electronic device, characterized in that: include: a storage device having a computer program stored thereon; A processing device, configured to execute the computer program in the storage device to implement the steps of the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Video classification model training method, device and equipment and storage medium
CN111401474A