Model processing method, device, computer equipment, storage medium and program product

By using multi-frame video frames to generate different three-dimensional data and comparing features between encoders in video pre-training, the problem of insufficient video content understanding in traditional methods is solved, and better video information learning and model generalization capabilities are achieved.

CN118246493BActive Publication Date: 2024-08-30TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410660906.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-27
Publication Date
2024-08-30
Estimated Expiration
2044-05-27

AI Technical Summary

Technical Problem

Traditional self-supervised pre-training methods are difficult to effectively utilize the temporal dimension information in three-dimensional video frames, resulting in insufficient understanding of video content and the inability to achieve fine-grained learning.

Method used

Multi-frame video frames are used to generate different three-dimensional data, and two encoders are used to process and compare features separately, and a contrast loss function at the image block level is constructed to train the pre-trained visual model, retain the temporal dimension information and perform fine-grained learning.

Benefits of technology

It improves video understanding capabilities and model generalization capabilities, can learn video information from semantic and pixel levels, and enhances the understanding and modeling capabilities of video content.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118246493B
    Figure CN118246493B
Patent Text Reader

Abstract

The present application relates to a model processing method, device, computer equipment, storage medium and program product. It can be applied in the field of artificial intelligence, and the method includes: obtaining a model to be trained including a first encoder and a second encoder; generating first three-dimensional data and second three-dimensional data based on multiple video frames; the first three-dimensional data and the second three-dimensional data are different three-dimensional data, and both include a target number of image blocks; obtaining the first feature of each image block generated when the first encoder processes the first three-dimensional data; obtaining the second feature of each image block generated when the second encoder processes the second three-dimensional data; determining the image block contrast loss based on the first feature and the second feature of each image block, and constructing a target loss function based on the image block contrast loss; training the model to be trained according to the target loss function to obtain a pre-trained visual model. The use of this method can improve the model training effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of machine learning, and in particular to a model processing method, apparatus, computer equipment, storage medium and program product. Background Art

[0002] With the rapid development of the Internet, the number of online videos has also shown a surge trend. Video has become the main medium for carrying a large amount of information. A video contains a huge amount of information. How to effectively use large-scale video data has become a hot area of ​​deep learning research and a major challenge facing academia and industry. Providing pre-trained models suitable for downstream tasks can not only improve model performance, but also reduce the number of iterations of downstream tasks.

[0003] Traditional self-supervised pre-training methods are usually based on two-dimensional image training, while three-dimensional videos contain richer semantic information. If the model parameters are initialized using the traditional self-supervised pre-training method to train a model of three-dimensional video frames, part of the time dimension information will usually be lost, and the understanding of the video content cannot be achieved well. Therefore, a model pre-training method for three-dimensional video frames is urgently needed. Summary of the invention

[0004] Based on this, it is necessary to provide a model processing method, device, computer equipment, computer-readable storage medium and computer program product to address the above technical problems.

[0005] In a first aspect, the present application provides a model processing method, comprising:

[0006] Acquire a model to be trained, where the model to be trained includes a first encoder and a second encoder;

[0007] Generate first three-dimensional data and second three-dimensional data based on multiple video frames; the first three-dimensional data and the second three-dimensional data are different three-dimensional data, and both include a target number of image blocks obtained by block division;

[0008] Obtaining a first feature corresponding to each image block, which is generated when the first encoder processes the first three-dimensional data;

[0009] Obtaining a second feature corresponding to each image block, which is generated when the second encoder processes the second three-dimensional data;

[0010] Determine the image block contrast loss according to the first feature and the second feature corresponding to each image block, and construct a target loss function based on the image block contrast loss;

[0011] The model to be trained is trained according to the target loss function to obtain a pre-trained visual model.

[0012] In a second aspect, the present application also provides a model processing device, comprising:

[0013] An acquisition module, used for acquiring a model to be trained, wherein the model to be trained includes a first encoder and a second encoder;

[0014] A generating module, configured to generate first three-dimensional data and second three-dimensional data based on multiple video frames; the first three-dimensional data and the second three-dimensional data are different three-dimensional data, and both include a target number of image blocks obtained by segmentation;

[0015] The acquisition module is further used to obtain the first feature corresponding to each image block, which is generated when the first encoder processes the first three-dimensional data;

[0016] The acquisition module is further used to obtain the second feature corresponding to each image block, which is generated when the second encoder processes the second three-dimensional data;

[0017] A determination module, configured to determine an image block contrast loss according to the first feature and the second feature corresponding to each image block, and construct a target loss function based on the image block contrast loss;

[0018] The training module is used to train the model to be trained according to the target loss function to obtain a pre-trained visual model.

[0019] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above-mentioned model processing method when executing the computer program.

[0020] In a fourth aspect, the present application also provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in the above-mentioned model processing method are implemented.

[0021] In a fifth aspect, the present application also provides a computer program product, including a computer program, which implements the steps in the above-mentioned model processing method when executed by a processor.

[0022] The above-mentioned model processing method, device, computer equipment, computer-readable storage medium and computer program product generate first three-dimensional data and second three-dimensional data based on multiple video frames, wherein the first three-dimensional data and the second three-dimensional data are different three-dimensional data, and both include a target number of image blocks obtained through block processing. Then, the first three-dimensional data and the second three-dimensional data are processed by two encoders respectively, and the features corresponding to each image block generated during the processing are compared one by one, and supervision is performed through contrast loss to minimize the distance between the same image blocks and maximize the distance between different pairs of image blocks. This self-supervised training method at the image block level retains the information of the time dimension in multiple video frames, and can perform fine-grained learning of video content, guiding the model to be trained to learn video information from the semantic and pixel levels, greatly improving the video understanding and model generalization capabilities of the visual model. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0024] Figure 1 An application environment diagram of a model processing method in an embodiment;

[0025] Figure 2 A schematic diagram of a flow chart of a model processing method in one embodiment;

[0026] Figure 3 is a model structure block diagram of a model to be trained in one embodiment;

[0027] Figure 4 A schematic diagram of the network structure of a 3D Swin Transformer in one embodiment;

[0028] Figure 5 A schematic diagram of the principle of a model processing method in one embodiment;

[0029] Figure 6 A schematic flow chart of steps for generating first three-dimensional data and second three-dimensional data based on multiple video frames in one embodiment;

[0030] Figure 7 A schematic diagram of a video frame segmentation result in one embodiment;

[0031] Figure 8is a flow chart of a step of determining the contrast loss of an image block according to the first feature of each image block and the second feature of each image block in one embodiment;

[0032] Fig. 9 A schematic diagram of a construction principle of feature contrast loss in one embodiment;

[0033] Fig.10 is a schematic diagram of the principle of a model processing method in another embodiment;

[0034] Fig.11 is a structural block diagram of a model processing device in an embodiment;

[0035] Fig.12 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0036] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application 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 application and are not used to limit the present application.

[0037] The model processing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The present application can be implemented by the terminal 102 or the server 104 separately to implement the model processing method, or it can be implemented by the terminal 102 and the server 104 in combination. Take the collaborative execution of the terminal 102 and the server 104 as an example to illustrate: the model to be trained can be deployed in advance on the server 104, the terminal 102 obtains the video sample, and extracts the video sample to obtain multiple frames of video frames, and generates the first three-dimensional data and the second three-dimensional data based on the multiple frames of video frames. The terminal 102 sends the first three-dimensional data and the second three-dimensional data to the server 104. After receiving the first three-dimensional data and the second three-dimensional data, the server 104 inputs the first three-dimensional data into the first encoder to obtain the first feature of each image block generated during the processing of the first encoder; the server 104 inputs the second three-dimensional data into the second encoder to obtain the second feature of each image block generated during the processing of the second encoder. The server 104 determines the image block contrast loss according to the first feature of each image block and the second feature of each image block, and constructs a target loss based on the image block contrast loss; and trains the model to be trained according to the target loss to obtain a pre-trained visual model.

[0038] Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. Head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The server 104 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services. The terminal and the server can be directly or indirectly connected via wired or wireless communication, and this application does not limit this.

[0039] The model processing method provided in this application involves artificial intelligence technology, especially computer vision technology and machine learning technology in artificial intelligence. Among them: Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that the machines have the functions of perception, reasoning and decision-making.

[0040] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. Basic artificial intelligence technologies generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, pre-trained model technology, operation / interaction systems, mechatronics and other technologies. Among them, the pre-trained model is also called a large model or a basic model. After fine-tuning, it can be widely used in downstream tasks in various major directions of artificial intelligence. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0041] Computer Vision (CV) is a science that studies how to make machines "see". To put it more specifically, it refers to using cameras and computers to replace human eyes to identify, follow and measure targets, and further perform image processing to make computer processing into images that are more suitable for human eye observation or transmission to instruments for detection. As a scientific discipline, computer vision studies related theories and technologies, and attempts to establish an artificial intelligence system that can obtain information from images or multidimensional data. Large model technology has brought important changes to the development of computer vision technology. Pre-trained models in the field of vision such as swin-transformer (a deep learning model based on transformer, transformer is also a deep learning model), ViT (vision transformer, a visual neural network), V-MOE (vision sparsely-gated mixture of experts networks, a sparse gated mixture of experts network in the visual field), MAE (masked autoencoders, a self-supervised learning model based on deep learning) can be quickly and widely applied to downstream specific tasks after fine tuning. Computer vision technology generally includes image processing, image recognition, image semantic understanding, image retrieval, OCR (Optical Character Recognition), video processing, video semantic understanding, video content / behavior recognition, three-dimensional object reconstruction, 3D technology, virtual reality, augmented reality, simultaneous positioning and map construction, as well as common biometric recognition technologies such as face recognition and fingerprint recognition.

[0042] Machine Learning (ML) is a multi-disciplinary subject involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and learning by induction. The pre-trained model is the latest development of deep learning, which integrates the above technologies.

[0043] The pre-trained visual model can be obtained by the model processing method provided in this application, and the model is a pre-trained model. The pre-training model (Pre-training model), also known as the cornerstone model or the large model, refers to a deep neural network (DNN) with large parameters, which is trained on a large amount of unlabeled data, and the function approximation ability of the large-parameter DNN is used to enable the PTM (pre-training model) to extract common features from the data, and after fine-tuning (fine tune), parameter efficient fine-tuning (PEFT), prompt-tuning (prompt tuning) and other technologies, it is suitable for downstream tasks. Therefore, the pre-training model can achieve ideal results in a few-shot or zero-shot scenario. PTM can be divided into language models (ELMO, BERT, GPT), visual models (swin-transformer, ViT, V-MOE), speech models (VALL-E), multimodal models (ViBERT, CLIP, Flamingo, Gato), etc. according to the data modality processed, where the multimodal model refers to a model that establishes two or more data modality feature representations. Pre-trained models are an important tool for outputting artificial intelligence generated content (AIGC) and can also serve as a general interface for connecting multiple specific task models.

[0044] The model training method of this application involves a self-supervised learning method. Before introducing the model processing method provided by this application in detail, the comparative learning in the self-supervised learning method is first introduced:

[0045] Contrastive learning is a self-supervised learning method whose main idea is to learn meaningful representations by comparing the similarities between data samples. In contrastive learning, the model is required to map different views of the same sample or similar instances from different samples into close representation spaces, while mapping instances from different categories into distant representation spaces. The goal of this method is to make similar samples close in the embedding space, while dissimilar samples are far away.

[0046] Traditional self-supervised schemes based on contrastive learning usually compare the features of a single sample image, focusing on semantic-level features. This method performs well in image-level self-supervised pre-training. However, when traditional contrastive learning is applied to the pre-training task of 3D videos, its limitations are usually revealed. First, videos contain richer semantic information, so contrastive learning methods that rely solely on feature-level learning cannot adequately learn and process the details of the video, that is, they cannot learn the video content in a fine-grained manner. Second, if the parameters of the 2D pre-trained model are used to initialize the model of the 3D video frame, part of the time dimension information is usually lost, making it impossible to better understand the video content.

[0047] In view of this, the present application has made improvements based on the idea of ​​contrastive learning and provided a model processing method suitable for video data, which can better learn video information from the semantic and pixel levels, and help improve video understanding and the generalization ability of the model.

[0048] In an exemplary embodiment, Figure 2 As shown, a model processing method is provided, and the method is applied to a computer device (the computer device can be specifically Figure 1 The method is described as an example of a terminal or server in FIG. 200 , including the following steps 202 to 212. Among them:

[0049] Step 202: Obtain a model to be trained, where the model to be trained includes a first encoder and a second encoder.

[0050] Among them, the model to be trained is a machine learning model that needs to be pre-trained, including a first encoder and a second encoder. The first encoder and the second encoder can be encoders with the same network structure but different parameter update methods, or encoders with certain differences in network structure but the same parameter update method, or encoders with differences in network structure and different parameter update methods. Parameter update methods include stochastic gradient descent method, momentum update method, etc. Among them, the momentum update method can include momentum gradient descent method, that is, calculating the exponentially weighted average of the gradient and using this value to update the parameter value.

[0051] In some embodiments, the first encoder may be an Encoder, and the second encoder may be a Momentum Encoder. The Encoder parameters are updated in a SGD (Stochastic Gradient Descent) manner, while the Momentum Encoder is updated in a momentum manner without the need for SGD back propagation.

[0052] It should be noted that, in the present application, two encoders of the model to be trained, one updates parameters by means of stochastic gradient descent, and the other updates parameters by means of momentum, the purpose of which is to keep certain differences between the two encoders during the training process, so as to facilitate comparative learning. In contrastive learning, two encoders (such as Online Encoder and Target Encoder) are usually used to calculate the similarity between samples. Momentum update can ensure that the parameters of TargetEncoder are the exponential moving averages of the parameters of Online Encoder, avoiding their excessive deviation during the training process. In addition, momentum update can be regarded as a regularization method, which constrains the complexity of the model by smoothing parameter updates, thereby improving the generalization ability of the model and avoiding overfitting.

[0053] Among them, the Online Encoder (online encoder) can specifically be the first encoder in the present application, and the Target Encoder (target encoder) can specifically be the second encoder in the present application.

[0054] Please refer to the following Figure 3 , Figure 3 FIG. 1 is a block diagram of a model structure of a model to be trained in an embodiment. Figure 3 As shown, the model to be trained includes a first encoder and a second encoder. The first encoder includes a backbone network, a projector, and a first predictor; the second encoder includes a backbone network, a projector, and a second predictor. The first predictor and the second predictor may be predictors of the same structure or different structures.

[0055] The backbone network is the basic network used by the model to be trained, which is used for feature extraction. The backbone network can use a traditional convolutional neural network (CNN) or a Transformer network. In view of the remarkable achievements of Transformer in the field of vision, in some embodiments, 3D Swin Transformer (a deformable attention model used in the video field, also known as Video Swin Transformer) can be selected as the backbone network for self-supervised training. For the detailed structure of 3D Swin Transformer, see Figure 4 ,like Figure 4As shown in the figure, the network structure of the 3D Swin Transformer includes multiple Video Swin Transformer Blocks (deformation attention structure blocks). The video (Video) composed of multiple video frames is divided into three-dimensional image blocks (3D patch Partition) and sent to the backbone network. It is processed in multiple stages by multiple Video Swin Transformer Blocks in the backbone network (for example, Figure 4 In one example, specifically, in the first stage, the input features are linearly embedded (Linear Embedding) and then processed by two Video Swin Transformer Blocks; in the second stage, the received features are patch merged (Patch Merging) and then processed by two Video Swin Transformer Blocks; in the third stage, the received features are patch merged and then processed by six Video Swin Transformer Blocks; in the fourth stage, the received features are patch merged and then processed by two Video Swin Transformer Blocks.

[0056] The projector is usually composed of multiple layers of fully connected layers, which are used to map the input features into a more discriminative space. In this application, the projector transforms the features output by the backbone network to promote the model to learn more meaningful feature representations. The design of this structure helps to improve the model's understanding of the data and improve the distinctiveness of features in contrastive learning tasks, thereby providing more effective initialized feature representations for downstream tasks. This unique design enables the first encoder and / or the second encoder to better capture the key features in the data, improves the generalization ability of the model in various tasks, and achieves significant performance improvements in practical applications.

[0057] The predictor (including the first predictor and the second predictor) may generally be composed of a pooling layer and / or a fully connected layer, which compresses the features input therein and maps them into a more discriminative space.

[0058] In some embodiments, the visual model obtained by pre-training in this case is a pre-trained first encoder, and its backbone network can be implemented based on Transformer. It can be understood that in other video tasks, the structure of the first encoder can be changed according to the needs of downstream tasks, such as Resnet (Residual Network, a deep convolutional neural network), Vit (vision transformer, a visual neural network) and other deep learning networks.

[0059] Step 204 , generating first three-dimensional data and second three-dimensional data based on multiple video frames; the first three-dimensional data and the second three-dimensional data are different three-dimensional data, and both include a target number of image blocks obtained by segmentation.

[0060] The three-dimensional data is data including a time dimension, and in this application, it can be video data with a time dimension. The first three-dimensional data and the second three-dimensional data are both obtained by processing multiple video frames, and both contain a certain amount of the same video content, but there are certain differences, so they are different three-dimensional data. The multiple video frames can be extracted from video samples, and the video samples are videos used as samples.

[0061] A patch is the smallest unit obtained by dividing a video frame. A video frame may include M (M is a positive integer greater than 1) image patches, and the three-dimensional data composed of N (N is a positive integer greater than 1) video frames includes the target number of N*M image patches.

[0062] In some embodiments, the computer device may perform block division and differential processing on the multiple video frames to obtain the first three-dimensional data and the second three-dimensional data. The timing of the block division and differential processing is not limited, and the block division may be performed first and then the differential processing; or the differential processing may be performed first and then the block division. The differential processing may specifically be at least one of transformation or masking.

[0063] In some embodiments, the computer device may first divide each video frame in the multiple video frames into blocks to obtain multiple video frames including a target number of image blocks. Then, the multiple video frames including the target number of image blocks may be subjected to a first process to obtain first three-dimensional data; and the multiple video frames including the target number of image blocks may be subjected to a second process to obtain second three-dimensional data. The first process and the second process are different processing methods.

[0064] Exemplarily, the first processing may be a certain data enhancement method, such as rotation; the second processing may be another different data enhancement method, such as cropping. For another example, the first processing may be a first masking processing, that is, masking part of the image blocks in the multi-frame video frames including the target number of image blocks; the second processing may be a second masking processing, that is, masking the image blocks at different positions in the multi-frame video frames including the target number of image blocks. For another example, the first processing may be no processing, and the second processing may be data enhancement or image block masking processing, etc.

[0065] In some embodiments, the differential processing may specifically be a transformation. The computer device may first perform a first transformation on the multiple video frames and then divide them into blocks to obtain first three-dimensional data; and perform a second transformation on the multiple video frames and then divide them into blocks to obtain second three-dimensional data. The first processing and the second processing are different processing methods. The first transformation may be a certain data enhancement method, such as rotation; the second transformation may be another different data enhancement method, such as cropping; or the first transformation may be no processing, and the second transformation may be a certain data enhancement method; or the first transformation may be a certain data enhancement method, and the second transformation may be no processing.

[0066] Step 206: Obtain a first feature corresponding to each image block, which is generated when the first encoder processes the first three-dimensional data.

[0067] It should be noted that the first encoder may include a preset structure and a first predictor. The preset structure is used to extract features from the first three-dimensional data, and the features extracted in this link include features corresponding to each image block. The first predictor is used to compress the features extracted from the preset structure to obtain a first output feature.

[0068] Specifically, the computer device may obtain the first feature corresponding to each image block generated by the first encoder during the feature extraction process of the first three-dimensional data. For example, please refer to Figure 3 , the preset structure in the first encoder may include a backbone network and a projector. The first feature corresponding to each image block obtained in step 206 may be a feature output by the backbone network of the first encoder, or a feature output by the projector of the first encoder, which is not limited in the embodiment of the present application.

[0069] Step 208: Obtain a second feature corresponding to each image block, which is generated when the second encoder processes the second three-dimensional data.

[0070] It should be noted that the second encoder may include a preset structure and a second predictor. The preset structure is used to extract features from the second three-dimensional data, and the features extracted in this link include features corresponding to each image block. The second predictor is used to compress the features extracted from the preset structure to obtain a second output feature. It is understood that the first predictor and the second predictor may be the same predictor or different predictors, and the embodiments of the present application do not limit this.

[0071] Specifically, the computer device may obtain the second features corresponding to each image block generated by the second encoder in the process of extracting features from the second three-dimensional data. Figure 3 , the preset structure in the second encoder may include a backbone network and a projector. The second feature corresponding to each image block obtained in step 208 may be a feature output by the backbone network of the first encoder, or a feature output by the projector of the first encoder, which is not limited in the embodiment of the present application.

[0072] Step 210: determine the image block contrast loss according to the first feature and the second feature corresponding to each image block, and construct a target loss function based on the image block contrast loss.

[0073] It should be noted that the image block in the first three-dimensional data has a corresponding relationship with the image block in the second three-dimensional data. Although there may be some differences between the image block at position i in the first three-dimensional data and the image block at position i in the second three-dimensional data, they can be considered to be the same image block in theory. The image block at position i in the first three-dimensional data and the image block at position j in the second three-dimensional data are clearly not the same image block. Wherein, i and j are both natural numbers.

[0074] Therefore, the computer device can determine the image block contrast loss according to the first feature and the second feature corresponding to each image block, and the purpose of the image block contrast loss is to minimize the distance between the same image blocks and maximize the distance between different image blocks. The distance between image blocks refers to the distance between the image block in the first three-dimensional data and the image block in the second three-dimensional data.

[0075] In some embodiments, for any image block i, the computer device may calculate the first distance between the first feature and the second feature of the image block i, and sum all the first distances to obtain a first sum value; the computer device respectively calculates the second distances between different image blocks and sums them to obtain a second sum value. Thus, the comparison value of the first sum value and the second sum value is used as the image block comparison loss. Among them, the comparison value is a value that can reflect the difference between two data, and can specifically be a ratio, a difference, or a value obtained by performing other mathematical operations.

[0076] Furthermore, the computer device can directly use the image block contrast loss as the target loss to construct a target loss function, or combine the image block contrast loss with other losses to obtain the target loss to construct a target loss function. The target loss function is a function with the target loss as a dependent variable.

[0077] Step 212: train the model to be trained according to the target loss function to obtain a pre-trained visual model.

[0078] Specifically, for the first encoder, the computer device can use the gradient descent method to adjust the parameters of the first encoder according to the target loss function, and the adjustment direction is to minimize the target loss. For the second encoder, the computer device can use the momentum update method to adjust the parameters of the second encoder.

[0079] After the training is completed, the computer device can continue to perform the above steps 204 to 210 for the next batch of samples to obtain the target loss of the next batch, so as to adjust the parameters of the first encoder and the second encoder again. In this way, the training is iterated continuously and stops when the training stop condition is reached to obtain a pre-trained visual model.

[0080] The training stop condition is a condition for stopping training, which may be that the performance of the first encoder reaches a preset performance, the change in the target loss is within a preset range, the preset number of training iterations is reached, etc. The pre-trained visual model may be a pre-trained first encoder, or a model constructed by a partial network structure and parameters in the pre-trained first encoder.

[0081] For example, please refer to Figure 5 , Figure 5 FIG. 1 is a schematic diagram showing the principle of a model processing method in an embodiment. Figure 5 As shown, the first encoder includes a backbone network, a projector and a first predictor; the second encoder includes a backbone network, a projector and a second predictor.

[0082] The computer device can perform multi-scale frame extraction on the video sample to obtain multiple video frames. The multiple video frames are divided into blocks, and then transformed, masked, etc. are processed to obtain first three-dimensional data and second three-dimensional data. The first three-dimensional data is input into the backbone network of the first encoder, and the second three-dimensional data is input into the backbone network of the second encoder. The first encoder processes the first three-dimensional data, and the second encoder processes the second three-dimensional data. The computer device obtains the first feature corresponding to each image block output by the projector of the first encoder, and obtains the second feature corresponding to each image block output by the backbone network of the second encoder. Then, the image block contrast loss is constructed according to the first feature and the second feature corresponding to each image block. The computer device can determine the target loss function based on the image block contrast loss, so as to train the model to be trained based on the target loss function.

[0083] The above-mentioned model processing method generates the first three-dimensional data and the second three-dimensional data based on multiple video frames, wherein the first three-dimensional data and the second three-dimensional data are different three-dimensional data, and both include a target number of image blocks. The first three-dimensional data and the second three-dimensional data are then processed by two encoders respectively, and the features corresponding to each image block generated during the processing are compared one by one, and supervision is performed through contrast loss to minimize the distance between the same image blocks and maximize the distance between different pairs of image blocks. This self-supervised training method at the image block level retains the information of the time dimension in multiple video frames, and can perform fine-grained learning of video content, guiding the model to be trained to learn video information from the semantic and pixel levels, greatly improving the video understanding and model generalization capabilities of the visual model.

[0084] It is understood that the terms "first", "second", etc. used in this application can be used to describe various elements in this article, but these elements are not limited by these terms. These terms are only used to distinguish a first element from another element. For example, without departing from the scope of this application, a first encoder can be referred to as a second encoder, and similarly, a first feature can be referred to as a second feature.

[0085] refer to Figure 6 In some embodiments, generating first three-dimensional data and second three-dimensional data based on multiple video frames includes the following steps:

[0086] Step 602: extract multiple video frames from the video sample as data to be processed.

[0087] Specifically, the computer device may extract multiple video frames from the video sample and use the extracted multiple video frames as the data to be processed. Exemplarily, the computer device may randomly extract from the video sample, or may extract in sequence according to the time sequence of each video frame. The number of multiple video frames may be a fixed number, such as a fixed value greater than 1, or a variable value greater than 1, or a value within a preset range.

[0088] In some embodiments, extracting multiple video frames from a video sample as data to be processed includes: determining a target value at that time from multiple preset values, and extracting multiple video frames from the video sample according to the target value; wherein the number of extracted video frames is the target value.

[0089] In order to improve the generalization of the model for scale processing of video data, this application designs a multi-scale time series input link. In this link, for each training, the computer device can determine the target value T of the current time from multiple preset values, and then extract T frames of video frames as the data to be processed. For example, T∈{4, 8, 16, 32}.

[0090] In the above embodiment, by designing a multi-scale video frame extraction process, the model can process videos of different scales, which greatly improves the applicability and generalization of the model.

[0091] Step 604 , performing block and differential processing on the data to be processed to obtain first three-dimensional data and second three-dimensional data.

[0092] Among them, block division refers to the process of dividing a video frame to obtain multiple image blocks. Transformation can also be understood as data enhancement, which can be resizing, rotation, cropping, or adding color.

[0093] For example, please refer to Figure 7 , Figure 7 The following is a schematic diagram of the video frame segmentation result, where each small block is an image block.

[0094] In some embodiments, the computer device may first divide the data to be processed into blocks and then perform differential processing to obtain first three-dimensional data and second three-dimensional data. Alternatively, the computer device may also perform differential processing on the data to be processed and then divide it into blocks to obtain first three-dimensional data and second three-dimensional data.

[0095] In some embodiments, the computer device may perform only one differential processing on the data to be processed, and obtain the first three-dimensional data and the second three-dimensional data based on the data to be processed before the differential processing and the data to be processed after the differential processing. In other embodiments, the computer device may perform two different processings on the data to be processed, and obtain the first three-dimensional data based on the data to be processed after the first processing, and obtain the second three-dimensional data based on the data to be processed after the second processing. The first processing and the second processing are different processings.

[0096] Exemplarily, the computer device may first perform block processing on the data to be processed to obtain the block-based data to be processed. Then, the block-based data to be processed is subjected to a first processing to obtain the first processed data. The computer device may use the block-based data to be processed as the first three-dimensional data, and use the block-based data subjected to the first processing as the second three-dimensional data.

[0097] Exemplarily, the computer device may first perform a first processing on the data to be processed, and then divide the data to be processed and the data after the first processing into blocks, respectively, to obtain first three-dimensional data and second three-dimensional data.

[0098] Exemplarily, the computer device may first perform block processing on the data to be processed to obtain the block-based data to be processed, and then perform two different processing on the block-based data to be processed respectively, and the data obtained after the two different processing are the first three-dimensional data and the second three-dimensional data.

[0099] Exemplarily, the computer device may first perform two different processes on the data to be processed, and then divide the data obtained after the two different processes into blocks to obtain the first three-dimensional data and the second three-dimensional data.

[0100] In the above embodiment, multiple video frames are extracted from the video sample as data to be processed, and the data to be processed are divided into blocks and differentiated to obtain first three-dimensional data and second three-dimensional data. This can not only improve the data processing efficiency, but also ensure that the first three-dimensional data and the second three-dimensional data still have certain differences while ensuring that the video information of the first three-dimensional data and the second three-dimensional data are overall consistent.

[0101] In some embodiments, the data to be processed is divided into blocks and differentially processed to obtain first three-dimensional data and second three-dimensional data, including: each video frame in the data to be processed is divided into blocks; a first transformation is performed on the divided data to be processed to obtain first candidate data, and a second transformation is performed on the divided data to be processed to obtain second candidate data; and a partial image block of at least one of the first candidate data or the second candidate data is covered to obtain the first three-dimensional data and the second three-dimensional data.

[0102] Specifically, the computer device may first divide each video frame in the data to be processed into blocks to obtain the divided data to be processed. Then, the divided data to be processed is subjected to a first transformation to obtain first candidate data, and the divided data to be processed is subjected to a second transformation to obtain second candidate data. The first transformation and the second transformation are different transformations, for example, the first transformation may be a rotation, and the second transformation may be a cropping.

[0103] Furthermore, the computer device may select data to be masked from the first candidate data or the second candidate data as the third candidate data, mask part of the image blocks in the third candidate data, and obtain the first three-dimensional data and the second three-dimensional data.

[0104] Exemplarily, the computer device may directly use the first candidate data as the first three-dimensional data, and cover part of the image blocks in the second candidate data to obtain the second three-dimensional data.

[0105] Exemplarily, the computer device may mask part of the image blocks in the first candidate data to obtain the first three-dimensional data, and directly use the second candidate data as the second three-dimensional data.

[0106] Exemplarily, the computer device may mask some image blocks in the first candidate data to obtain the first three-dimensional data, and mask some image blocks in the second candidate data to obtain the second three-dimensional data, wherein the masked image blocks in the first candidate data are at least partially different from the masked image blocks in the second candidate data.

[0107] In the above embodiment, the data to be processed is divided into blocks and transformed to obtain the first candidate data and the second candidate data. Under the premise of ensuring the consistency of the video content of the first candidate data and the second candidate data, there may be certain differences. Then, part of the image blocks of at least one of the first candidate data or the second candidate data are covered to obtain the first three-dimensional data and the second three-dimensional data. The first three-dimensional data and the second three-dimensional data that are different and lack some video information can help the model learn the video information at the pixel level, thereby improving the video modeling ability of the model. Moreover, the first three-dimensional data and the second three-dimensional data generated by the above method can also have certain performance differences under the premise of the overall consistency of the video information, which increases the difficulty of model learning and enables the trained model to better understand the video content.

[0108] In some embodiments, the candidate data to be masked is used as the third candidate data, and the masking process includes: obtaining a mask matrix, and performing matrix multiplication operation on the mask matrix and the third candidate data to mask part of the image blocks in the third candidate data.

[0109] The mask matrix is ​​a matrix of the same size as the matrix to be masked, and the element values ​​thereof are 0 or 1. The matrix to be masked in this application is also the third candidate data, and an element in the matrix to be masked is an image block in the third candidate data.

[0110] Specifically, the computer device may use the candidate data to be masked as the third candidate data. It is understandable that the third candidate data may be the first candidate data, or the second candidate data, or include the first candidate data and the second candidate data. For any third candidate data, the computer device may multiply the mask matrix with the third candidate data to mask at least part of the image blocks in the third candidate data. At least part of the image blocks are masked means that the pixel information of at least part of the image blocks in the target number of image blocks is uniformly set to a preset value, such as 0 or 1. It is understandable that the masking in the present application is also a mask.

[0111] For example, the mask mentioned in the present application can be a block mask. Assume that the third candidate data is x∈C*T*H*W, the size of the image block is 2*4*4, and the block mask operation is performed on the three dimensions of the third candidate data x∈C*T*H*W. Where T is the time length, H and W are the width and height of the image respectively, and C is the channel dimension. According to the size of the image block, it can be seen that the format of the third candidate data is transformed into , the mask matrix Then, the computer device may randomly initialize the masking matrix, and the value of the elements in the masking matrix is ​​0 or 1. Features after masking The calculation is as follows: .

[0112] In the above embodiment, the third candidate data is masked by a mask matrix to improve the masking efficiency. By masking a certain proportion of the video layer information, the model can learn the video information at the pixel level, and then combined with the contrast loss of the image block for training, the model can learn the video information at the semantic level. In this way, the model can be well guided to learn video information from the semantic and pixel levels, greatly improving the video understanding and model generalization capabilities of the visual model.

[0113] Please refer to Figure 8 In some embodiments, determining the image block contrast loss according to the first feature and the second feature corresponding to each image block includes:

[0114] Step 802: Determine a first distance of an image block according to a first feature and a second feature of an image block at the same position.

[0115] Specifically, for any position i, the computer device can calculate the first feature and the second feature of the image block at the position i, and calculate the first distance. The position mentioned in this embodiment refers to the position of the image block in the data to be processed. The calculation method of the first distance can be cosine distance, Euclidean distance, Manhattan distance, etc., which is not limited in this embodiment of the present application.

[0116] Step 804 , determining a second distance between different image blocks according to a first feature of the first image block and a second feature of the second image block; the first image block and the second image block are at different positions.

[0117] Specifically, the computer device may calculate the second distance based on the first feature of the image block at position i and the second feature of the image block at position j. The second distance may be calculated by cosine distance, Euclidean distance, Manhattan distance, etc., which is not limited in the present embodiment.

[0118] Step 806, determining the image block contrast loss according to the first distance and the second distance; the learning direction based on the image block contrast loss is to minimize the first distance and maximize the second distance.

[0119] Furthermore, the computer device may determine the image block contrast loss according to each first distance and each second distance. The learning direction of the image block contrast loss is to minimize the first distance and maximize the second distance.

[0120] In one implementation, the computer device may sum all the first distances and sum all the second distances, thereby taking a contrast value between the sum of the first distances and the sum of the second distances as the image block contrast loss.

[0121] In another implementation, for an image block at any position i, the computer device calculates the first distance between the first feature and the second feature of the image block at the position i, and also calculates the second distances between the first feature of the image block at the position i and the second features of the image blocks at other positions, thereby obtaining a contrast value between the first distance between the first feature and the second feature of the image block at the position i and the sum of the second distances between the first feature of the image block at the position i and the second features of the image blocks at other positions. In this way, the computer device can sum or average the contrast values ​​at each position to obtain the image block contrast loss.

[0122] Exemplarily, the first feature of the image block output by the first encoder is assumed to be ,in represents the number of image blocks of the first three-dimensional data or the second three-dimensional data, d represents the feature dimension; the second feature of the image block output by the second encoder is Then use contrast loss for supervision, minimize the distance between the same patch, maximize the distance between different patches, and get the image block contrast loss as:

[0123] in, is a hyperparameter, A1 refers to the first encoder, A2 refers to the second encoder, is the first feature of the image block at position i generated by the first encoder, is the second feature of the image block at position i generated by the second encoder, is the second feature of the image block at position j generated by the second encoder.

[0124] In the above embodiment, contrast loss is used for supervision to minimize the distance between the same image blocks and maximize the distance between different image blocks, which can guide the model to learn important information in the video from the semantic and pixel levels, and help improve video understanding and the generalization ability of the model.

[0125] In some embodiments, constructing a target loss based on an image block contrast loss includes: constructing a target loss function based on an image block contrast loss and a feature contrast loss. The process of determining the feature contrast loss includes: obtaining a first output feature obtained after a first encoder processes the first three-dimensional data; obtaining a second output feature obtained after a second encoder processes the second three-dimensional data; and determining the feature contrast loss based on the first output feature, the second output feature, and the feature of the negative sample.

[0126] In some embodiments, the target loss of the present application may also include a feature contrast loss. The feature contrast loss is calculated based on a first output feature obtained after the first encoder processes the first three-dimensional data and a second output feature obtained after the second encoder processes the second three-dimensional data.

[0127] It can be understood that the first three-dimensional data and the second three-dimensional data are generated by the same data to be processed in the video sample, and it can be considered that the video information between the two data is highly consistent. Therefore, the second three-dimensional data can be used as a positive sample of the first three-dimensional data, and the three-dimensional data generated by other data to be processed can be used as a negative sample of the first three-dimensional data.

[0128] Therefore, the computer device can determine the third distance between the first three-dimensional data and the positive sample, and the fourth distance between the first three-dimensional data and each negative sample. Thus, the feature contrast loss is determined based on the third distance and the sum of the fourth distances. The purpose of the feature contrast loss is to guide the model to be trained to learn a meaningful representation by comparing the similarities between the data. Among them, the calculation method of the distance between features can be specifically cosine distance, Euclidean distance, Manhattan distance, etc., which is not limited in the embodiments of the present application.

[0129] In some embodiments, the learning direction based on feature contrast loss is to minimize the distance between similar samples and maximize the distance between different samples. Similar samples are the first three-dimensional data and the second three-dimensional data generated by the same data to be processed mentioned in this embodiment. Different samples are the first three-dimensional data and the second three-dimensional data generated by different data to be processed mentioned in this embodiment. The data to be processed is a plurality of video frames extracted from the video sample.

[0130] For example, please refer to Fig. 9 , Fig. 9 FIG. 4 is a schematic diagram of the construction principle of feature contrast loss in one embodiment. Fig. 9 As shown, the first three-dimensional data is input into the first encoder to obtain the first output feature q, and the second three-dimensional data is input into the second encoder to obtain the second output feature k+, and the features of each negative sample (such as k0, k1, k2, etc.) are obtained. Based on the difference between the first output feature and the second output feature, and the difference between the first output feature and the features of each negative sample, a feature contrast loss is constructed.

[0131] It should be noted that, usually, the number of negative samples is equal to the batch size, but due to the limitation of GPU resources, the sufficiency of negative samples cannot be ensured. Therefore, the present application adopts a preset storage queue (memory bank) to store the features of negative samples. During the training process, the features of the negative samples stored in the preset storage queue are obtained by extracting features of the negative samples by the second encoder. For the first training batch (batch), the computer device may first extract a preset number of samples from the training sample set, perform feature extraction through the second encoder, and store the extracted features in the preset storage queue. The features stored in the preset storage queue are the features of the negative samples required for the first batch training. After the first batch training is completed, the second output features used in the first batch training are updated to the preset storage queue, and a part of the features are eliminated from the end of the preset storage queue, so that the number of features stored in the preset storage queue remains unchanged at the preset number. In this way, the features of the negative samples stored in the preset storage queue are updated for each batch of training.

[0132] In this way, each time the feature contrast loss is calculated, a certain amount of negative samples can be directly selected from the preset storage queue. This method makes the features of the negative samples obtained from the preset storage queue close to the features encoded by the second encoder. Whenever the batch is updated, the features of the old negative samples will be removed from the queue, and then the features obtained in the current batch will be used to fill the queue to further maintain consistency with the encoding of the second encoder.

[0133] In a specific embodiment, please refer to Fig.10 , Fig.10 FIG. 2 is a schematic diagram showing the principle of a model processing method in another embodiment. Fig.10 As shown, the first encoder includes a backbone network, a projector and a first predictor; the second encoder includes a backbone network, a projector and a second predictor.

[0134] The computer device can perform multi-scale frame extraction on the video sample to obtain multiple video frames. The multiple video frames are divided into blocks, and then transformed, masked, etc. are processed to obtain first three-dimensional data and second three-dimensional data. The first three-dimensional data is input into the backbone network of the first encoder, and the second three-dimensional data is input into the backbone network of the second encoder. The first encoder processes the first three-dimensional data, and the second encoder processes the second three-dimensional data. The computer device obtains the first feature of each image block output by the projector of the first encoder, and obtains the second feature of each image block output by the backbone network of the second encoder. Then, the image block contrast loss is constructed according to the first feature and the second feature corresponding to each image block. The computer device obtains the first output feature output by the first predictor, obtains the second output feature output by the second predictor, and determines the feature contrast loss based on the first output feature, the second output feature, and the features of the negative samples stored in the queue. The computer device can determine the target loss function based on the image block contrast loss and the feature contrast loss, so as to train the model to be trained based on the target loss function.

[0135] In the above embodiment, a first output feature is obtained after the first encoder processes the first three-dimensional data, and a second output feature is obtained after the second encoder processes the second three-dimensional data. Based on the first output feature, the second output feature, and the feature of the negative sample, the feature contrast loss can be determined, so that the model can learn in the direction of minimizing the distance between similar samples and maximizing the distance between different samples, so that the model can better learn the important information in the video to better understand the video content.

[0136] In some embodiments, based on the first output feature, the second output feature, and the features of the negative samples, a feature contrast loss is determined, including: determining a third distance between the first output feature and the second output feature; determining a fourth distance between the first output feature and the features of each negative sample; determining a feature contrast loss based on the third distance and the fourth distance; and the learning direction based on the feature contrast loss is to minimize the third distance and maximize the fourth distance.

[0137] Specifically, the computer device may calculate the third distance between the first output feature and the second output feature. And calculate the fourth distance between the first output feature and the feature of each negative sample. Thus, the comparison value between the third distance and the sum of each fourth distance is calculated, and the comparison value is used as the feature comparison loss. Among them, the comparison value is a value that can reflect the difference between two data, and can be a ratio, a difference, or a value obtained by performing other mathematical operations.

[0138] Exemplarily, the computer device may calculate the feature contrast loss using the following formula:

[0139] ; where q is the first output feature, k+ is the second output feature, and k m is the feature of the mth negative sample, K is the total number of negative samples, is a hyperparameter.

[0140] In the above embodiment, the feature contrast loss is constructed by the third distance between the first three-dimensional data and the positive sample, and the fourth distance between the first three-dimensional data and the negative sample, so that the model can learn in the direction of minimizing the distance between similar samples and maximizing the distance between different samples, so that the model can better learn the important information in the video to better understand the video content.

[0141] In some embodiments, the first encoder and the second encoder both include a preset structure, the preset structure includes a backbone network and a projector, the first feature is a feature output by the projector of the first encoder, and the second feature is a feature output by the backbone network of the second encoder, or the first feature is a feature output by the backbone network of the first encoder, and the second feature is a feature output by the projector of the second encoder.

[0142] Specifically, please refer to Figure 3 The first encoder and the second encoder may both include a preset structure, which is the main structure of the encoder and is used to realize feature extraction. In the design of the present application, the preset structure includes two parts, one is a backbone network and the other is a projector.

[0143] In some embodiments, the first feature and the second feature used to construct the image block contrast loss may be features of the output of the same network layer in the first encoder and the second encoder. For example, the first feature may be a feature of the backbone network output of the first encoder, and the second feature may be a feature of the backbone network output of the first encoder, or the first feature may be a feature of the projector output of the first encoder, and the second feature may be a feature of the projector output of the first encoder.

[0144] In other embodiments, in order to increase the difficulty of model training, the first feature and the second feature used to construct the image block contrast loss may be features of the outputs of the corresponding different network layers in the first encoder and the second encoder. For example, the first feature is the feature output by the projector of the first encoder, and the second feature is the feature output by the backbone network of the second encoder, or the first feature is the feature output by the backbone network of the first encoder, and the second feature is the feature output by the projector of the second encoder.

[0145] In the above embodiment, by constructing the image block contrast loss through the features of the outputs of different network layers corresponding to the first encoder and the second encoder, the difficulty of model training can be increased, and the model's understanding of the video content can be improved, so that the pre-trained visual model can better model the video content and improve the model training effect.

[0146] In some embodiments, the first encoder further includes a first predictor, and the second encoder further includes a second predictor, and the first predictor and the second predictor are asymmetric structures with respect to each other.

[0147] Specifically, the structures of the first predictor in the first encoder and the second predictor in the second encoder are asymmetric, aiming to ensure that a certain degree of asymmetry is introduced in feature learning to promote better feature learning and representation. Exemplarily, the first predictor may include a compression layer and a mapping layer, and the second predictor may only include a compression layer. In some embodiments, the compression layer may be implemented by maximum pooling or mean pooling.

[0148] In the above embodiment, maintaining the inconsistency of the structures of the first encoder and the second encoder can increase the difficulty of model learning, be more conducive to network optimization, and improve the generalization performance of the model.

[0149] It can be understood that the visual model pre-trained by the model processing method mentioned in the above embodiments can be retrained based on the actual downstream tasks and put into downstream tasks.

[0150] For example, with the development of Internet technology, various video applications have emerged, and a large amount of video data is pouring into major video applications every day. Taking news applications as an example, multi-label recognition in downstream tasks requires labeling and recommending labels for all videos. A large amount of unlabeled video data continues to pour in, and it takes a lot of manpower and financial resources to label a noise-free and sizable dataset. In order to make the model perform best on the newly added data and support continuous iteration with the addition of new labels, a model with strong generalization ability becomes very important, which can greatly reduce the number of iterations and the amount of training data of the downstream model.

[0151] In view of this, in some embodiments, the method also includes a model retraining step, which includes: obtaining training samples and category labels of the training samples; the training samples include videos; inputting the training samples into a pre-trained visual model, processing them through the pre-trained visual model to obtain a predicted category; and retraining the pre-trained visual model based on the difference between the predicted category and the category label to obtain a video processing model.

[0152] The training samples include videos, and the category label is the category to which the video belongs, such as variety shows, ancient style, modern style, TV series, reality shows, movies, etc. After the computer device completes pre-training of the training model through the model processing method mentioned in the above embodiment, the first encoder obtained by pre-training can be used as a pre-trained visual model, and the visual model can be retrained through the training samples and the category labels of the training samples. After the training is completed, a video processing model is obtained, which can be used for multi-label recognition or video classification, etc.

[0153] In some embodiments, the computer device may input the training samples into the pre-trained visual model, process the training samples through the pre-trained visual model, obtain the predicted category, construct a loss function for retraining according to the difference between the predicted category and the category label, and adjust the parameters of the pre-trained visual model through the loss function. Among them, the loss function may be a MSE (mean-square error) function. In this way, the pre-trained visual model is iteratively trained continuously through the training samples and category labels until the training end condition of the retraining is reached, and a trained video processing model is obtained. Among them, the training end condition of the retraining may be that the performance of the visual model reaches the preset performance, the change in the target loss during the retraining process is within a preset range, or the preset number of training iterations is reached. In some embodiments, for the video classification model, if a new category label appears, the video classification model may also be retrained based on the training samples of the new category label so that it can adapt to the new category label more quickly. The use of the pre-trained visual model in this application helps to speed up the convergence speed of downstream tasks, improve its recognition performance, and adapt to the new label more quickly. In this way, a small amount of data with new labels can be used to easily support the output of new labels.

[0154] In the above embodiment, after obtaining the pre-trained visual model, retraining can be performed using training samples and category labels to obtain a video processing model suitable for downstream tasks.

[0155] In some other scenarios, the downstream task may also be a task such as video retrieval. For example, the computer device may use the preset structure in the pre-trained first encoder to build a video retrieval model. Exemplarily, the database may store features corresponding to each video and corresponding label information. The label information may specifically be the video name of the video, the category to which the video belongs, the relevant information included in the video, etc. The computer device receives a video retrieval request, extracts the video carried in the video retrieval request, uses the video retrieval model to extract features of the video, calculates the similarity between the extracted features and the features stored in the database, and uses the videos in the database that meet the preset similarity conditions and / or the label information of the videos that meet the preset similarity conditions as the retrieval results of the video retrieval request, and feeds back the retrieval results to the user. Among them, the preset similarity condition may be that the similarity is greater than or equal to the preset similarity threshold, or the preset top L (L is a positive integer greater than or equal to 1) names with the largest similarity.

[0156] It can be understood that the general visual model obtained by pre-training in this application is suitable for downstream tasks such as multi-label recognition, video classification, video retrieval, and recognition of low-quality and high-quality videos based on video learning. This technology can provide applicable pre-trained models for most downstream tasks based on video. Taking video label recognition as an example, the following performance comparison is made between the visual model without using a pre-trained model and the visual model using the video self-supervised pre-training framework proposed in this application:

[0157]

[0158] Table 1 Performance comparison

[0159] It can be clearly seen from Table 1 above that the visual model pre-trained using the video self-supervised pre-training framework proposed in this application is applied to downstream tasks, with significant improvements in performance.

[0160] In a specific embodiment, the model processing method includes the following contents:

[0161] A model to be trained is obtained, wherein the model to be trained includes a first encoder and a second encoder. The first encoder includes a backbone network, a projector, and a first predictor; the second encoder includes a backbone network, a projector, and a second predictor, wherein the first predictor and the second predictor are asymmetric structures.

[0162] The target value of the current time is determined from a plurality of preset values, and a plurality of video frames are extracted from the video sample according to the target value; wherein the number of the extracted video frames is the target value.

[0163] Each video frame in the data to be processed is divided into blocks, a first transformation is performed on the divided data to be processed to obtain first candidate data, and a second transformation is performed on the divided data to be processed to obtain second candidate data.

[0164] A mask matrix is ​​obtained, and a matrix multiplication operation is performed on the mask matrix and the first candidate data or the second candidate data to obtain the first three-dimensional data and the second three-dimensional data.

[0165] When the first encoder processes the first three-dimensional data, a first feature of each image block output by the projector of the first encoder is obtained, and when the second encoder processes the second three-dimensional data, a second feature of each image block output by the backbone network of the second encoder is obtained.

[0166] According to the first feature and the second feature of the image block at the same position, the first distance of the same image block is determined; according to the first feature of the first image block and the second feature of the second image block, the second distance of different image blocks is determined; the first image block and the second image block are at different positions; according to the first distance and the second distance, the image block contrast loss is determined; the learning direction based on the image block contrast loss is to minimize the first distance and maximize the second distance.

[0167] A first output feature of a first predictor output in a first encoder is obtained, and a second output feature of a second predictor output in a second encoder is obtained.

[0168] Determine a third distance between the first output feature and the second output feature; determine a fourth distance between the first output feature and the features of each negative sample; determine a feature contrast loss based on the third distance and the fourth distance; the learning direction based on the feature contrast loss is to minimize the third distance and maximize the fourth distance.

[0169] A target loss function is constructed based on image block contrast loss and feature contrast loss, and the model to be trained is trained according to the target loss function to obtain a pre-trained visual model.

[0170] The present application provides a video-based self-supervised pre-training strategy to generate a general visual model, with the help of the robustness of Transformer in the visual field (the Backbone framework of the present application can be implemented based on Transformer). In addition, the present application proposes a model processing method, and the target loss includes two losses, one is the contrast loss at the patch feature level, and the other is the contrast loss of the output feature. Among them, in the contrast loss at the patch feature level, the present application randomly masks a certain proportion of the video level information, and then encodes the features of the occluded image and the unoccluded image through two different encoders, and then compares the patch features output by the transformer one by one, and supervises through the contrast loss, minimizes the distance between the same patch pairs, and maximizes the distance between different patch pairs, improves the stability of model training and the model's ability to understand the video, further improves the model performance, and ultimately improves the model's ability to model the video. The visual model obtained by pre-training in the present application can have a strong ability to model video content, and can provide pre-training parameters with good generalization for downstream tasks.

[0171] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0172] Based on the same inventive concept, the embodiment of the present application also provides a model processing device for implementing the model processing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more model processing device embodiments provided below can refer to the limitations on the model processing method above, and will not be repeated here.

[0173] In an exemplary embodiment, Fig.11 As shown, a model processing device 1100 is provided, comprising: an acquisition module 1101, a generation module 1102, a determination module 1103 and a training module 1104, wherein:

[0174] The acquisition module is used to acquire the model to be trained, where the model to be trained includes a first encoder and a second encoder.

[0175] A generating module is used to generate first three-dimensional data and second three-dimensional data based on multiple video frames; the first three-dimensional data and the second three-dimensional data are different three-dimensional data, and both include a target number of image blocks obtained by block division.

[0176] The acquisition module is further used to obtain the first feature corresponding to each image block, which is generated when the first encoder processes the first three-dimensional data.

[0177] The acquisition module is further used to obtain the second feature corresponding to each image block, which is generated when the second encoder processes the second three-dimensional data.

[0178] The determination module is used to determine the image block contrast loss according to the first feature and the second feature corresponding to each image block, and to construct a target loss function based on the image block contrast loss.

[0179] The training module is used to train the model to be trained according to the target loss function to obtain a pre-trained visual model.

[0180] In some embodiments, the generation module is specifically used to: extract multiple video frames from the video sample as data to be processed; and perform block and differential processing on the data to be processed to obtain first three-dimensional data and second three-dimensional data.

[0181] In some embodiments, the generation module is specifically used to: determine the current target value from a plurality of preset values, and extract a plurality of video frames from the video sample according to the target value; wherein the number of extracted video frames is the target value.

[0182] In some embodiments, the generation module is specifically used to: divide each video frame in the data to be processed into blocks; perform a first transformation on the blocked data to be processed to obtain first candidate data, and perform a second transformation on the blocked data to be processed to obtain second candidate data; and cover a part of the image blocks of at least one of the first candidate data or the second candidate data to obtain first three-dimensional data and second three-dimensional data.

[0183] In some embodiments, the generating module is specifically used to: obtain a mask matrix, and perform a matrix multiplication operation on the mask matrix and the third candidate data to cover part of the image blocks in the third candidate data.

[0184] In some embodiments, the determination module is specifically used to determine the first distance of the same image block based on the first feature and the second feature of the image block at the same position; determine the second distance of different image blocks based on the first feature of the first image block and the second feature of the second image block; the first image block and the second image block are at different positions; determine the image block contrast loss based on the first distance and the second distance; the learning direction based on the image block contrast loss is to minimize the first distance and maximize the second distance.

[0185] In some embodiments, the determination module is specifically used to obtain a first output feature obtained after the first encoder processes the first three-dimensional data; obtain a second output feature obtained after the second encoder processes the second three-dimensional data; determine the feature contrast loss based on the first output feature, the second output feature, and the feature of the negative sample. Construct a target loss function based on the image block contrast loss and the feature contrast loss.

[0186] In some embodiments, the determination module is specifically used to determine the third distance between the first output feature and the second output feature; determine the fourth distance between the first output feature and the features of each negative sample; determine the feature contrast loss based on the third distance and the fourth distance; the learning direction based on the feature contrast loss is to minimize the third distance and maximize the fourth distance.

[0187] In some embodiments, the first encoder and the second encoder both include a preset structure, the preset structure includes a backbone network and a projector, the first feature is a feature output by the projector of the first encoder, and the second feature is a feature output by the backbone network of the second encoder, or the first feature is a feature output by the backbone network of the first encoder, and the second feature is a feature output by the projector of the second encoder.

[0188] In some embodiments, the first encoder further includes a first predictor, and the second encoder further includes a second predictor, and the first predictor and the second predictor are asymmetric structures with respect to each other.

[0189] In some embodiments, the device also includes a retraining module for obtaining training samples and category labels of the training samples; the training samples include videos; the training samples are input into a pre-trained visual model, processed by the pre-trained visual model to obtain a predicted category; based on the difference between the predicted category and the category label, the pre-trained visual model is retrained to obtain a video processing model.

[0190] Each module in the above-mentioned model processing device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0191] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal or a server. The internal structure diagram thereof may be as follows: Fig.12 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a model processing method is implemented.

[0192] Those skilled in the art will understand that Fig.12The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0193] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.

[0194] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0195] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0196] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0197] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0198] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0199] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A model processing method, characterized in that: The method comprises: Acquire a model to be trained, where the model to be trained includes a first encoder and a second encoder; Generate first three-dimensional data and second three-dimensional data based on multiple video frames; the first three-dimensional data and the second three-dimensional data are different three-dimensional data, and both include a target number of image blocks obtained by block division; Obtaining a first feature corresponding to each image block, which is generated when the first encoder processes the first three-dimensional data; Obtaining a second feature corresponding to each image block, which is generated when the second encoder processes the second three-dimensional data; Determine an image block contrast loss according to the first feature and the second feature corresponding to each image block; the image block contrast loss is used to minimize the distance between the same image blocks and maximize the distance between different image blocks; the distance between the image blocks refers to the distance between the image block in the first three-dimensional data and the image block in the second three-dimensional data; Constructing a target loss function based on the image block contrast loss; The model to be trained is trained according to the target loss function to obtain a pre-trained visual model.

2. The method according to claim 1, characterized in that The generating of the first three-dimensional data and the second three-dimensional data based on the multiple video frames comprises: Extracting multiple video frames from the video sample as data to be processed; The data to be processed is divided into blocks and differentiated to obtain first three-dimensional data and second three-dimensional data.

3. The method according to claim 2, characterized in that The extracting a plurality of video frames from the video sample as data to be processed includes: A target value for the current time is determined from a plurality of preset values, and a plurality of video frames are extracted from the video sample according to the target value; wherein the number of the extracted video frames is the target value.

4. The method according to claim 2, characterized in that The step of dividing and differentially processing the data to be processed to obtain first three-dimensional data and second three-dimensional data includes: Dividing each video frame in the data to be processed into blocks; Performing a first transformation on the data to be processed after being divided into blocks to obtain first candidate data, and performing a second transformation on the data to be processed after being divided into blocks to obtain second candidate data; A partial image block of at least one of the first candidate data or the second candidate data is masked to obtain first three-dimensional data and second three-dimensional data.

5. The method according to claim 4, characterized in that The candidate data to be masked is used as the third candidate data, and the masking process includes: A mask matrix is ​​obtained, and a matrix multiplication operation is performed on the mask matrix and the third candidate data to cover part of the image blocks in the third candidate data.

6. The method according to claim 1, characterized in that The determining the image block contrast loss according to the first feature and the second feature corresponding to each image block includes: Determine a first distance of the same image block according to the first feature and the second feature of the image block at the same position; Determining a second distance between different image blocks according to a first feature of a first image block and a second feature of a second image block; the first image block and the second image block are at different positions; An image block contrast loss is determined according to the first distance and the second distance; and a learning direction based on the image block contrast loss is to minimize the first distance and maximize the second distance.

7. The method according to claim 1, characterized in that The constructing a target loss function based on the image block contrast loss includes: Constructing a target loss function based on the image block contrast loss and the feature contrast loss; The process of determining the feature contrast loss includes: Obtaining a first output feature obtained after the first encoder processes the first three-dimensional data; Obtaining a second output feature obtained after the second encoder processes the second three-dimensional data; A feature contrast loss is determined based on the first output feature, the second output feature, and features of negative samples.

8. The method according to claim 7, characterized in that The determining the feature contrast loss based on the first output feature, the second output feature, and the feature of the negative sample includes: determining a third distance between the first output feature and the second output feature; Determine fourth distances between the first output feature and features of each negative sample; A feature contrast loss is determined according to the third distance and the fourth distance; and a learning direction based on the feature contrast loss is to minimize the third distance and maximize the fourth distance.

9. The method according to claim 1, characterized in that: Both the first encoder and the second encoder include a preset structure, which includes a backbone network and a projector. The first feature is a feature output by the projector of the first encoder, and the second feature is a feature output by the backbone network of the second encoder. Alternatively, the first feature is a feature output by the backbone network of the first encoder, and the second feature is a feature output by the projector of the second encoder.

10. The method according to claim 9, characterized in that The first encoder further includes a first predictor, and the second encoder further includes a second predictor, and the first predictor and the second predictor are asymmetric structures to each other.

11. The method according to any one of claims 1 to 10, characterized in that The method further comprises: Obtaining training samples and category labels of the training samples; the training samples include videos; Inputting the training sample into a pre-trained visual model, processing the sample through the pre-trained visual model, and obtaining a predicted category; According to the difference between the predicted category and the category label, the pre-trained visual model is retrained to obtain a video processing model.

12. A model processing device, characterized in that: The device comprises: An acquisition module, used for acquiring a model to be trained, wherein the model to be trained includes a first encoder and a second encoder; A generating module, configured to generate first three-dimensional data and second three-dimensional data based on multiple video frames; the first three-dimensional data and the second three-dimensional data are different three-dimensional data, and both include a target number of image blocks obtained by segmentation; The acquisition module is further used to obtain the first feature corresponding to each image block, which is generated when the first encoder processes the first three-dimensional data; The acquisition module is further used to obtain the second feature corresponding to each image block, which is generated when the second encoder processes the second three-dimensional data; A determination module, configured to determine an image block contrast loss according to the first feature and the second feature corresponding to each image block; the image block contrast loss is used to minimize the distance between the same image blocks and maximize the distance between different image blocks; the distance between image blocks refers to the distance between the image block in the first three-dimensional data and the image block in the second three-dimensional data; and construct a target loss function based on the image block contrast loss; The training module is used to train the model to be trained according to the target loss function to obtain a pre-trained visual model.

13. The device according to claim 12, characterized in that The generation module is specifically used for: Extracting multiple video frames from the video sample as data to be processed; The data to be processed is divided into blocks and differentiated to obtain first three-dimensional data and second three-dimensional data.

14. The device according to claim 13, characterized in that The generation module is specifically used for: A target value for the current time is determined from a plurality of preset values, and a plurality of video frames are extracted from the video sample according to the target value; wherein the number of the extracted video frames is the target value.

15. The device according to claim 13, characterized in that The generation module is specifically used for: Dividing each video frame in the data to be processed into blocks; Performing a first transformation on the data to be processed after being divided into blocks to obtain first candidate data, and performing a second transformation on the data to be processed after being divided into blocks to obtain second candidate data; A partial image block of at least one of the first candidate data or the second candidate data is masked to obtain first three-dimensional data and second three-dimensional data.

16. The device according to claim 15, characterized in that The generation module is specifically used for: The candidate data to be masked is used as the third candidate data; a mask matrix is ​​obtained, and a matrix multiplication operation is performed on the mask matrix and the third candidate data to mask part of the image blocks in the third candidate data.

17. The device according to claim 12, characterized in that The determination module is specifically used for: Determine a first distance of the same image block according to the first feature and the second feature of the image block at the same position; Determining a second distance between different image blocks according to a first feature of a first image block and a second feature of a second image block; the first image block and the second image block are at different positions; determining an image block contrast loss according to the first distance and the second distance; The learning direction based on the image block contrast loss is to minimize the first distance and maximize the second distance.

18. The device according to claim 12, characterized in that The determination module is specifically used for: Constructing a target loss function based on the image block contrast loss and the feature contrast loss; The process of determining the feature contrast loss includes: Obtaining a first output feature obtained after the first encoder processes the first three-dimensional data; Obtaining a second output feature obtained after the second encoder processes the second three-dimensional data; A feature contrast loss is determined based on the first output feature, the second output feature, and features of negative samples.

19. The device according to claim 18, characterized in that The determination module is specifically used for: determining a third distance between the first output feature and the second output feature; Determine fourth distances between the first output feature and features of each negative sample; A feature contrast loss is determined according to the third distance and the fourth distance; and a learning direction based on the feature contrast loss is to minimize the third distance and maximize the fourth distance.

20. The device according to claim 12, characterized in that Both the first encoder and the second encoder include a preset structure, which includes a backbone network and a projector. The first feature is a feature output by the projector of the first encoder, and the second feature is a feature output by the backbone network of the second encoder. Alternatively, the first feature is a feature output by the backbone network of the first encoder, and the second feature is a feature output by the projector of the second encoder.

21. The device according to claim 20, characterized in that The first encoder further includes a first predictor, and the second encoder further includes a second predictor, and the first predictor and the second predictor are asymmetric structures to each other.

22. The device according to any one of claims 12 to 21, characterized in that The apparatus further comprises a retraining module, configured to: Obtaining training samples and category labels of the training samples; the training samples include videos; Inputting the training sample into a pre-trained visual model, processing the sample through the pre-trained visual model, and obtaining a predicted category; According to the difference between the predicted category and the category label, the pre-trained visual model is retrained to obtain a video processing model.

23. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.

24. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.

25. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.

Citation Information

Patent Citations

  • Image retrieval model training method and device, equipment and storage medium

    CN114020950A

  • Video representation learning method and device, video processing method and device, medium and equipment

    CN114359769A

  • Medical image coding network pre-training method and device, equipment and storage medium

    CN115994558A

  • Systems and Methods for Contrastive Learning of Visual Representations

    US20210327029A1