Video recommendation method, device, electronic device and storage medium
Through video feature extraction and similarity calculation based on the neural network model, the problem of insufficient video recommendation accuracy in the existing technology is solved, accurate video recommendation is achieved, repeated video recommendation is avoided, and user experience is improved.
Patent Information
- Application Number
- CN202410450433.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-15
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-04-15
AI Technical Summary
Existing video recommendation methods have shortcomings in recommendation accuracy and are difficult to distinguish between duplicate videos and similar videos, resulting in inaccurate recommendation results and affecting user experience.
The video feature extraction method based on the first neural network model is used to train the model through comparative learning loss and similarity ranking loss, extract video features, calculate the similarity between videos, and recommend videos based on the similarity to avoid recommending duplicate videos.
It improves the accuracy of video recommendation, enhances the ability to sort videos by similarity, reduces the consumption of computing resources, improves model training efficiency, and ensures the accuracy of recommendation results.
Smart Images

Figure CN118035496B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence, and in particular to a video recommendation method, device, electronic device and storage medium. Background Art
[0002] Currently, on the video recommendation platform, videos are recommended to subjects based on the content that the subjects are interested in, in order to enhance the subject's stickiness. When determining the video to recommend to the subject, similar videos can be searched in the video library containing a large number of videos based on the target video that the subject is interested in, and videos with high similarity are recommended to the subject first.
[0003] However, in the related art, the recommendation accuracy of recommending videos to objects is low. Summary of the invention
[0004] The embodiments of the present disclosure provide a video recommendation method, device, electronic device and storage medium, which can improve the accuracy of video recommendation.
[0005] According to one aspect of the present disclosure, a video recommendation method is provided, comprising:
[0006] Acquire a query video and a candidate video library, wherein the candidate video library includes multiple candidate videos;
[0007] Performing video feature extraction on the query video and the multiple candidate videos based on a first neural network model to obtain query video features and multiple candidate video features, wherein the first neural network model is obtained based on target loss training, and the target loss includes a first loss and a second loss, wherein the first loss is a comparative learning loss calculated based on video features of an augmented video of a sample video and a preset negative sample video, and the second loss is a similarity ranking loss calculated based on video features of the sample video and cut-out videos of multiple sizes, wherein the cut-out videos of multiple sizes are videos obtained by cutting out the sample video in multiple sizes in a video frame dimension;
[0008] Calculating the similarity between the query video feature and each of the candidate video features;
[0009] Video recommendations are made based on the similarity.
[0010] According to one aspect of the present disclosure, a video recommendation device is provided, comprising:
[0011] An acquisition unit, configured to acquire a query video and a candidate video library, wherein the candidate video library includes a plurality of candidate videos;
[0012] A feature extraction unit is used to extract video features of the query video and the multiple candidate videos based on a first neural network model to obtain query video features and multiple candidate video features, wherein the first neural network model is obtained based on target loss training, and the target loss includes a first loss and a second loss, wherein the first loss is a comparative learning loss calculated based on video features of an augmented video of a sample video and a preset negative sample video, and the second loss is a similarity ranking loss calculated based on video features of the sample video and cut-out videos of multiple sizes, wherein the cut-out videos of multiple sizes are videos obtained by cutting out the sample video in multiple sizes in a video frame dimension;
[0013] A calculation unit, used for calculating the similarity between the query video feature and each of the candidate video features;
[0014] The recommendation unit is used to recommend videos according to the similarity.
[0015] Optionally, in one implementation, the training process of the first neural network model comprises the following steps:
[0016] Acquire multiple first sample videos and multiple preset negative sample videos, and perform video amplification on each of the first sample videos to obtain multiple amplified videos, wherein the amplified videos include the first sample videos and videos obtained by performing video amplification on the first sample videos;
[0017] Performing video feature extraction on the amplified video based on the first neural network model to obtain an amplified video feature, and performing video feature extraction on the multiple preset negative sample videos based on the second neural network model to obtain multiple negative sample video features;
[0018] Calculate the contrastive learning loss based on the amplified video feature and the negative sample video feature to obtain a first loss;
[0019] Cut each of the first sample videos into multiple sizes on a video frame dimension to obtain multiple cut videos, and extract video features from the first sample video and the multiple cut videos based on the first neural network model to obtain first sample video features and multiple cut video features;
[0020] Calculating a similarity ranking loss based on the first sample video feature, the multiple intercepted video features, and a similarity ranking relationship between the multiple intercepted videos and the first sample video to obtain a second loss;
[0021] The parameters of the first neural network model are updated according to the first loss and the second loss.
[0022] Optionally, in one implementation, the training process of the first neural network model further includes:
[0023] Obtaining a plurality of second sample videos and a classification label corresponding to each of the second sample videos;
[0024] Extracting video features from the second sample video based on the first neural network model to obtain second sample video features;
[0025] Classifying the second sample video feature based on a preset classification network layer to obtain a classification prediction probability value;
[0026] Calculate the classification loss based on the classification prediction probability value and the classification label to obtain a third loss;
[0027] The updating of the parameters of the first neural network model according to the first loss and the second loss includes:
[0028] The parameters of the first neural network model are updated according to the first loss, the second loss and the third loss.
[0029] Optionally, in one implementation, the performing video amplification on each of the first sample videos to obtain a plurality of amplified videos includes:
[0030] Performing time-series amplification on the first sample video to obtain a first sub-amplified video;
[0031] Performing spatial amplification on the first sample video to obtain a second sub-amplified video;
[0032] spatially amplifying the first sub-amplified video to obtain a third sub-amplified video;
[0033] A plurality of augmented videos are determined according to the first sub-amplified video, the second sub-amplified video, the third sub-amplified video, and the first sample video.
[0034] Optionally, in one implementation, before performing time series amplification on the first sample video to obtain the first sub-amplified video, the training process of the first neural network model further includes:
[0035] Splitting the first sample video into a plurality of video segments, and extracting a video frame from each of the video segments to obtain a plurality of video frames;
[0036] The step of performing time-series amplification on the first sample video to obtain a first sub-amplified video includes:
[0037] Performing time-sequential amplification on the multiple video frames to obtain multiple first sub-amplified video frames;
[0038] The extracting video features from the amplified video based on the first neural network model to obtain amplified video features includes:
[0039] Video features are extracted from multiple-frame amplified video frames based on a first neural network model to obtain amplified video features. The multiple-frame amplified video frames include the multiple-frame video frames, the multiple-frame first sub-amplified video frames obtained only based on time amplification, the multiple-frame second sub-amplified video frames obtained only based on spatial amplification, and the multiple-frame third sub-amplified video frames obtained based on both time amplification and spatial amplification.
[0040] Optionally, in one implementation, the first neural network model includes a first network layer and a second network layer, and the step of extracting video features from multiple augmented video frames based on the first neural network model to obtain augmented video features includes:
[0041] Based on the first network layer, image feature extraction is performed on the multiple augmented video frames to obtain multiple frame features;
[0042] The plurality of frame features are subjected to feature fusion based on the second network layer to obtain an augmented video feature.
[0043] Optionally, in one implementation, the performing feature fusion on the multiple frame features based on the second network layer to obtain the amplified video features includes:
[0044] Based on performing a linear transformation on the plurality of frame features, a first intermediate matrix, a second intermediate matrix and a third intermediate matrix are obtained;
[0045] performing normalization processing on the transposed multiplication of the first intermediate matrix and the second intermediate matrix, and multiplying the normalization processing result by the third intermediate matrix to obtain multiple frame fusion results;
[0046] An average value of the fusion results of the multiple frames is calculated to obtain the augmented video feature.
[0047] Optionally, in one implementation, the feature extraction unit is specifically used to:
[0048] Extracting a plurality of query video frames from the query video, and extracting a plurality of candidate video frames from each of the candidate videos;
[0049] Extracting image features from the multiple query video frames based on the first network layer to obtain multiple query frame features, and extracting image features from the multiple candidate video frames based on the first network layer to obtain multiple candidate frame features;
[0050] Based on the second network layer, feature fusion is performed on the multiple query frame features to obtain query video features, and based on the second network layer, feature fusion is performed on the multiple candidate frame features corresponding to each candidate video to obtain multiple candidate video features.
[0051] Optionally, in one implementation, the feature extraction unit is specifically used to:
[0052] Splitting the query video into a plurality of query video segments, and splitting each of the candidate videos into a plurality of candidate video segments;
[0053] Extracting a query video frame from each query video segment to obtain multiple query video frames;
[0054] A candidate video frame is extracted from each of the candidate video segments to obtain multiple candidate video frames corresponding to each of the candidate videos.
[0055] Optionally, in one implementation, the training process of the first neural network model further includes:
[0056] Get the momentum update coefficients of the model parameters;
[0057] The parameters of the second neural network model are updated based on the updated parameters of the first neural network model and the momentum update coefficient.
[0058] Optionally, in one implementation, the recommendation unit is specifically configured to:
[0059] Determine a video among the multiple candidate videos whose similarity to the query video is less than a preset threshold as a first target video;
[0060] Sorting the plurality of first target videos in descending order according to the similarity with the query video, and determining a preset number of videos ranked first as second target videos;
[0061] Recommending a plurality of the second target videos to the recommendation object.
[0062] According to one aspect of the present disclosure, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-mentioned video recommendation method when executing the computer program.
[0063] According to one aspect of the present disclosure, a computer-readable storage medium is provided, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the video recommendation method as described above is implemented.
[0064] According to one aspect of the present disclosure, a computer program product is provided. The computer program product includes a computer program. The computer program is read and executed by a processor of a computer device, so that the computer device executes the video recommendation method as described above.
[0065] The video recommendation method in the disclosed embodiment obtains a query video and a candidate video library, wherein the candidate video library includes multiple candidate videos; extracts video features of the query video and the multiple candidate videos based on a first neural network model to obtain query video features and multiple candidate video features, wherein the first neural network model is trained based on a target loss, wherein the target loss includes a first loss and a second loss, wherein the first loss is a comparative learning loss calculated based on video features of an augmented video of a sample video and a preset negative sample video, and the second loss is a similarity ranking loss calculated based on video features of the sample video and cutout videos of multiple sizes, wherein the cutout videos of multiple sizes are videos obtained by cutting out the sample video in multiple sizes in a video frame dimension; calculates the similarity between the query video feature and each candidate video feature; and recommends videos based on the similarity.
[0066] In this way, the video recommendation method of the embodiment of the present disclosure trains the first neural network model for extracting video features by designing a first loss and a second loss, wherein the first loss is a comparative learning loss calculated based on the video features of an augmented video of a sample video and a preset negative sample video, and the second loss is a similarity ranking loss calculated based on the video features of the sample video and captured videos of multiple sizes, thereby enabling the first neural network model to learn better identical video recognition capabilities and video similarity ranking capabilities; in this way, video recommendations based on the trained first neural network model can improve the accuracy of video recommendations.
[0067] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or understood by practicing the present disclosure. The purpose and other advantages of the present disclosure can be realized and obtained by the structures particularly pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] The accompanying drawings are used to provide further understanding of the technical solution of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the technical solution of the present disclosure and do not constitute a limitation on the technical solution of the present disclosure.
[0069] Figure 1 is a system architecture diagram of a video recommendation method according to an embodiment of the present disclosure;
[0070] Figure 2A-2D is a schematic diagram of an interface in which an embodiment of the present disclosure is applied to a scenario in which a short video is recommended to an object;
[0071] Figure 3 is a flowchart of a video recommendation method according to an embodiment of the present disclosure;
[0072] Figure 4 is a flowchart of training a first neural network model according to one embodiment of the present disclosure;
[0073] Figure 5 is a schematic diagram of performing temporal amplification and spatial amplification based on a first sample video according to an embodiment of the present disclosure;
[0074] Figure 6 is a schematic diagram of performing time-series expansion based on multiple video frames extracted from a first sample video according to an embodiment of the present disclosure;
[0075] Figure 7 is a schematic diagram of a first neural network model according to an embodiment of the present disclosure;
[0076] Figure 8 is a schematic diagram of intercepting a first sample video in multiple sizes according to an embodiment of the present disclosure;
[0077] Fig. 9 is a schematic diagram of a similarity matrix according to an embodiment of the present disclosure;
[0078] Fig.10 is another flowchart of a video recommendation method according to an embodiment of the present disclosure;
[0079] Fig.11 is a schematic diagram of training a first neural network model according to an embodiment of the present disclosure;
[0080] Fig.12 is a structural diagram of a video recommendation device according to an embodiment of the present disclosure;
[0081] Fig.13 is a terminal structure diagram for implementing various methods according to an embodiment of the present disclosure;
[0082] Fig.14 It is a server structure diagram for implementing various methods according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0083] In order to make the purpose, technical solution and advantages of the present disclosure more clear, the present disclosure 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 disclosure and are not used to limit the present disclosure.
[0084] Before further describing the embodiments of the present disclosure in detail, the nouns and terms involved in the embodiments of the present disclosure are described. The nouns and terms involved in the embodiments of the present disclosure are subject to the following interpretations:
[0085] Deep neural network: It is a multi-layer unsupervised neural network. Deep neural network uses the output features of the previous layer as the input of the next layer for feature learning. After layer-by-layer feature mapping, the features of the existing spatial samples are mapped to another feature space, so as to learn to have better feature expression for the existing input. Deep neural network has multiple nonlinear mapping feature transformations and can fit highly complex functions.
[0086] Gradient descent algorithm: A method for minimizing the loss function. It calculates the gradient of the loss function at the current position and updates the parameters in the direction of gradient descent to find the optimal solution that minimizes the value of the loss function.
[0087] Transformer model: It is a deep learning model based on the multi-head self-attention mechanism, which is used to capture the dependencies between different positions in the input sequence. The self-attention mechanism allows the model to assign different weights to each word in the input sequence, thereby better capturing long-distance dependencies. The multi-head attention technology divides the input sequence into multiple subspaces, performs self-attention calculations on each subspace, and then concatenates the results. This allows the model to focus on information at different positions at the same time, improving the model's expressiveness.
[0088] Normalization (softmax function): compress a K-dimensional vector containing any real number into another K-dimensional vector so that each element ranges between (0,1) and the sum of all elements is 1.
[0089] Euclidean distance: can be used to calculate the similarity between two vectors. Specifically, all corresponding elements of the two vectors can be subtracted, the squares of the differences can be added, and finally the square root can be taken to get the Euclidean distance between the two vectors. The smaller the Euclidean distance, the closer the two vectors are.
[0090] Manhattan distance: It can also be used to calculate the similarity between two vectors. Specifically, all elements of the two vectors can be subtracted and the absolute value sum can be taken to get the Manhattan distance between the two vectors. The smaller the Manhattan distance, the closer the two vectors are.
[0091] Cosine similarity: The cosine value of the angle between two vectors in a vector space is used to measure the similarity between two individuals. The closer the cosine value is to 1, the closer the angle is to 0, indicating that the two vectors are more similar. The closer the cosine value is to 0, the closer the angle is to 90 degrees, indicating that the two vectors are less similar.
[0092] In the related art, when recommending videos to an object based on a target video that the object is interested in, a video that is a duplicate of the target video is often recommended to the object. This is because when recommending videos, videos with high similarity to the target video are recommended to the object first, and when calculating the similarity between the target video and other videos in the related art, the similarity between the target video and the duplicate video and the similarity between the target video and other similar videos are relatively small. For example, the similarity between the target video and the duplicate video is 0.99, and the similarity between the target video and another similar video is 0.97. Therefore, it is difficult for the video recommendation method in the related art to distinguish duplicate videos from similar videos with high similarity, so that a video that is a duplicate of the target video is recommended to the object. The target video is a video that the object has already viewed, and recommending the duplicate video to the object again will affect the object's experience of browsing videos. Therefore, the recommendation accuracy of the video recommendation method in the related art is low. In this regard, the embodiment of the present disclosure provides a video recommendation method in order to improve the accuracy of video recommendation.
[0093] Figure 1 1 is a system architecture diagram used in the video recommendation method according to an embodiment of the present disclosure, which includes a terminal 140, the Internet 130, a gateway 120, a server 110, and the like.
[0094] The terminal 140 includes various forms such as desktop computers, laptop computers, PDAs (personal digital assistants), mobile phones, vehicle-mounted terminals, home theater terminals, and dedicated terminals. In addition, it can be a single device or a collection of multiple devices. For example, multiple devices are connected through a local area network and work together using a common display device, forming a terminal 140. The terminal 140 can also communicate with the Internet 130 in a wired or wireless manner to exchange data.
[0095] The server 110 refers to a computer system that can provide certain services to the terminal 140. Compared with the ordinary terminal 140, the server 110 has very high requirements in terms of stability, security, performance, etc. The server 110 can be a high-performance computer in a network platform, a cluster of multiple high-performance computers, a part of a high-performance computer (such as a virtual machine), a combination of parts of multiple high-performance computers (such as virtual machines), etc.
[0096] The gateway 120 is also called an internetwork connector or a protocol converter. The gateway realizes network interconnection at the transport layer and is a computer system or device that acts as a converter. The gateway is a translator between two systems that use different communication protocols, data formats or languages, or even completely different architectures. At the same time, the gateway can also provide filtering and security functions. The message sent by the terminal 140 to the server 110 must be sent to the corresponding server 110 through the gateway 120. The message sent by the server 110 to the terminal 140 must also be sent to the corresponding terminal 140 through the gateway 120.
[0097] The video recommendation method of the embodiment of the present disclosure may be implemented completely on the terminal 140 ; may be implemented completely on the server 110 ; or may be implemented partially on the terminal 140 and the other partially on the server 110 .
[0098] The embodiments of the present disclosure can be applied in various scenarios, such as Figure 2A-2D The scenario shown in FIG. 1 is a scenario of recommending a short video to an object.
[0099] When recommending short videos to an object, other short videos can be recommended based on the short videos that the object is interested in. Figure 2A As shown, the subject views the short video through the terminal 140, and the terminal 140 includes a video display area 210, in which the short videos recommended to the subject can be displayed. When the subject views a short video, if the subject is interested in the video, the subject can mark the video as "like" through the video marking control 211.
[0100] The marked short video is used as the target short video, and candidate short videos similar to the target short video are found from the candidate short video library and recommended to the object. Figure 2B As shown, it includes candidate short video M1, candidate short video M2, candidate short video M3 and candidate short video M4. The result of calculating the similarity between the target short video and multiple candidate short videos using the video recommendation method of the embodiment of the present disclosure is as follows Figure 2C As shown, the similarity between the target short video and the candidate short video M1 is 0.999, the similarity with the candidate short video M2 is 0.756, the similarity with the candidate short video M3 is 0.564, and the similarity with the candidate short video M4 is 0.125. The similarity between the target short video and the candidate short video M1 is extremely high. If the candidate short video M1 is recommended to the object, the object may become fatigued due to repeatedly watching two extremely similar videos, affecting the object's viewing experience. Therefore, the candidate short video M1 can be determined as a duplicate video of the target short video and does not need to be recommended to the object. The candidate short video M2 has the highest similarity ranking among the remaining candidate short videos. Therefore, as Figure 2DAs shown, the candidate short video M2 is recommended to the subject first. The subject is also interested in the candidate short video M2, so the subject can also mark this video as "like" through the video marking control 211.
[0101] In the above process, a candidate short video that is the same as the target video can be determined from multiple candidate short videos to avoid recommending this candidate short video to the object. At the same time, a video with a high similarity can be queried from other videos and recommended to the object, which is conducive to improving the accuracy of the recommendation and further improving the object's experience in the video browsing process.
[0102] According to an embodiment of the present disclosure, a video recommendation method is provided. The video recommendation method provided by the embodiment of the present disclosure can be applied to Figure 2A-2D As shown in the scenario of recommending short videos to an object. Figure 3 FIG. 1 is a flow chart of a video recommendation method provided by the present disclosure. The video recommendation method may include:
[0103] Step 310: Obtain a query video and a candidate video library.
[0104] The query video may be a reference video for recommending videos to the subject, or may be a video content that the subject is interested in in the video recommendation application. The query video may be obtained based on an interest event that occurs to the subject in the video recommendation application. An interest event may be an event used to determine that the subject is interested in a video in the video recommendation application, for example, the subject likes or comments on the video; the duration of viewing the video by the subject accounts for a predetermined proportion of the total duration of the video, etc. In response to the triggering of an interest event for a video by the subject in the video recommendation application, the video may be obtained as the query video.
[0105] The candidate video library includes multiple candidate videos. Based on the query video, similar candidate videos can be found in the candidate video library and recommended to the object. Candidate videos with high similarity to the query video are likely to be of interest to the object.
[0106] The candidate videos in the candidate video library can be all videos in the complete video library of the video recommendation application. When a video publisher publishes a video in the video recommendation application, the video can be stored in the complete video library for searching for videos similar to the query video for recommendation.
[0107] The candidate videos in the candidate video library can also be obtained by screening all the videos in the complete video library corresponding to the video recommendation application. In one embodiment, the candidate videos obtained from the complete video library can be screened using video tags. In order to classify and manage a large number of videos, the videos in the complete video library can carry category tags. The category tags can be selected by the video publisher when publishing the video, for example, "movie", "funny" and "music". When screening using video tags, the target category tag of the query video can be obtained, and the video corresponding to the target category tag is obtained from the complete video library as the candidate video. For example, the target category tag of the query video is "music", and all videos with the category tag of "music" are obtained from the complete video library to form a candidate video library. The candidate video library obtained by screening all the videos in the complete video library can reduce the number of candidate videos in the candidate video library, which is conducive to improving the efficiency of querying recommended videos from the candidate video library.
[0108] Step 320: extract video features from the query video and multiple candidate videos based on the first neural network model to obtain query video features and multiple candidate video features.
[0109] In some embodiments, the first neural network model can be a deep neural network for extracting features from videos. The first neural network model is trained based on a target loss, and the target loss includes a first loss and a second loss. The first loss is a comparative learning loss calculated based on the video features of an augmented video of a sample video and a preset negative sample video. The second loss is a similarity ranking loss calculated based on the video features of the sample video and captured videos of multiple sizes. The captured videos of multiple sizes are videos obtained by capturing the sample video in multiple sizes in the video frame dimension. The training process of the first neural network will be described in detail below, and the construction process and function of the first loss and the second loss will be described in detail in the description.
[0110] Specifically, in one embodiment, Figure 4 As shown, the training process of the first neural network model includes the following steps:
[0111] Step 410: obtaining a plurality of first sample videos and a plurality of preset negative sample videos, and performing video amplification on each first sample video to obtain a plurality of amplified videos;
[0112] Step 420: extracting video features from the augmented video based on the first neural network model to obtain augmented video features, and extracting video features from multiple preset negative sample videos based on the second neural network model to obtain multiple negative sample video features;
[0113] Step 430: Calculate the contrastive learning loss based on the amplified video features and the negative sample video features to obtain a first loss;
[0114] Step 440: intercept each first sample video in multiple sizes on the video frame dimension to obtain multiple intercepted videos, and extract video features from the first sample video and the multiple intercepted videos based on the first neural network model to obtain first sample video features and multiple intercepted video features;
[0115] Step 450: Calculate the similarity ranking loss based on the first sample video feature, the multiple intercepted video features, and the similarity ranking relationship between the multiple intercepted videos and the first sample video to obtain a second loss;
[0116] Step 460: Update the parameters of the first neural network model according to the first loss and the second loss.
[0117] In step 410, the first sample video is a video sample used to train the first neural network model, and multiple first sample videos can constitute a training set. The multiple first sample videos can include videos of multiple video types so that the trained first neural network model can be applicable to general scenarios. The multiple first sample videos can also be videos in specific scenes, such as animation videos, news videos, or landscape videos. Training the first neural network model with the first sample videos of specific scenes can enable the first neural network model to achieve better video recommendation effects in specific scenarios. The first sample videos can be obtained from a public video data website or from multiple video recommendation applications.
[0118] The preset negative sample video may be a video that is different from the first sample video in content, and is used to assist the first sample video in training the first neural network model. When a video is different from the first sample video, the video may be used as a preset negative sample video.
[0119] The preset negative sample video may also be a video that has little correlation with the video type feature of the first sample video. For example, if the first sample video is a landscape video, the preset negative sample video may be an animal video or a food video, etc.; if the first sample video is an animation video, the preset negative sample video may be a news video or a landscape video, etc.
[0120] The preset negative sample video can be obtained from the negative sample video library. The negative sample video library can be pre-constructed based on multiple first sample videos, which contains a large number of preset negative sample videos, such as 500,000 preset negative sample videos. Since the amount of data in the negative sample video library is relatively large, multiple preset negative sample videos and multiple first sample videos can be extracted from the negative sample video library to train the first neural network model. For example, 63,355 of the 500,000 preset negative sample videos in the negative sample video library are extracted for training the first neural network model with multiple first sample videos. During the training process of the first neural network model, multiple rounds of training can be performed using multiple first sample videos. In each round of training, multiple preset negative sample videos that are different from those in the previous round of training can be obtained from the negative sample video library to avoid the problem of overfitting of the model due to the use of the same preset negative sample video for training in multiple rounds of training, which is conducive to improving the generalization of the first neural network model.
[0121] Constructing a negative sample video library based on multiple first sample videos can pre-acquire videos with content differences from multiple first sample videos to construct a negative sample video library. When training the first neural network model, multiple preset negative sample videos and multiple first sample videos can be randomly selected from the negative sample video library to train the first neural network model.
[0122] Constructing a negative sample video library based on multiple first sample videos can also construct a negative sample video library based on the video types of multiple first sample videos. When multiple first sample videos include videos of multiple video types, videos of multiple video types can be obtained to construct a negative sample video library. When training the first neural network model, multiple preset negative sample videos of other video types can be obtained from the negative sample video library based on the video type of each first sample video to train the first neural network model. For example, when multiple first sample videos include landscape videos, animation videos, and news videos, other types of videos other than the above three types can be obtained from the negative sample video library as preset negative sample videos for comparative learning with the first sample videos. When multiple first sample videos are videos in a specific scene, a large number of videos in other scenes different from the scene can be obtained to construct a negative sample video library.
[0123] Amplifying each first sample video may obtain multiple amplified videos, wherein the amplified videos include the first sample video and a video obtained by amplifying the first sample video. Amplifying the first sample video may increase the number of training samples used to train the first neural network model. The amplified video obtained by amplifying the first sample video may be used as a repeated video of the first sample video to train the first neural network model.
[0124] In one implementation, each first sample video is amplified to obtain a plurality of amplified videos, including:
[0125] Performing time-series amplification on the first sample video to obtain a first sub-amplified video;
[0126] Performing spatial amplification on the first sample video to obtain a second sub-amplified video;
[0127] Performing spatial amplification on the first sub-amplified video to obtain a third sub-amplified video;
[0128] A plurality of augmented videos are determined according to the first sub-amplified video, the second sub-amplified video, the third sub-amplified video, and the first sample video.
[0129] Temporal expansion can refer to adjusting the first sample video in the time dimension of the first sample video to achieve an expansion effect. For example, deleting certain frames in the first sample video, speeding up or slowing down the first sample video, randomly inserting frames of other videos into the first sample video, etc. Each temporal expansion operation can obtain a corresponding first sub-expanded video, and multiple temporal expansion operations can also be superimposed.
[0130] Spatial augmentation may refer to adjusting the first sample video in the frame dimension of the first sample video to achieve an augmentation effect. For example, adding Gaussian noise to each frame in the first sample video, adjusting the contrast, brightness and saturation of the frame image, etc.; performing operations such as horizontal flipping, upside down flipping, rotating, cropping or translating the frame image; adding other content to each frame image, such as identification symbols or text, etc. When performing spatial augmentation, the spatial augmentation operation for each frame image in the first sample video can be the same. Each spatial augmentation operation can obtain a corresponding second sub-augmented video, and multiple spatial augmentation operations can also be superimposed.
[0131] When performing video amplification on the first sample video, the first sample video can also be simultaneously subjected to temporal amplification and spatial amplification, that is, the first sub-amplified video obtained by temporal amplification can be further subjected to spatial amplification to obtain a third sub-amplified video. Similarly, the second sub-amplified video obtained by spatial amplification can be further subjected to temporal amplification, and the video obtained in such an amplification sequence can also be regarded as the third sub-amplified video. Multiple temporal amplification operations and multiple spatial amplification operations can be arbitrarily combined.
[0132] like Figure 5 A schematic diagram of video amplification of a first sample video is shown. Figure 5In the example, the first sample video includes continuous frames f1 to f8, and the width of each frame can indicate the duration of the frame. The wider the width, the longer the duration of each frame and the slower the frame rate. The first sample video is temporally amplified to obtain a first sub-amplified video. The temporal amplification operation performed on the first sub-amplified video on the basis of the first sample video includes: deleting frame f2; inserting frame f9 that does not belong to the first sample video between frame f5 and frame f6; and slowing down the first sample video as a whole. The first sample video is spatially amplified to obtain a second sub-amplified video. The spatial amplification operation performed on the second sub-amplified video on the basis of the first sample video includes: rotating each frame counterclockwise by 30 degrees; adjusting the brightness and saturation of each frame (not shown in the figure). The first sub-amplified video after temporal amplification is spatially amplified to obtain a third sub-amplified video. The spatial amplification operation performed on the third sub-amplified video on the basis of the first sub-amplified video includes: flipping each frame upside down; and adding Gaussian noise to each frame (not shown in the figure).
[0133] Through temporal amplification and spatial amplification, video amplification is achieved from multiple aspects, which improves the comprehensiveness of the amplified video. The multiple amplified videos amplified from a first sample video are duplicate videos. Therefore, using the amplified videos amplified in multiple ways to train the first neural network model can improve the generalization and robustness of the model in feature extraction of duplicate videos, thereby improving the accuracy of feature extraction by the first neural network model.
[0134] The above implementation method performs temporal amplification and spatial amplification based on the complete first sample video. In another implementation method, before performing temporal amplification on the first sample video to obtain the first sub-amplified video, it also includes: splitting the first sample video into multiple video segments, and extracting video frames from each video segment to obtain multiple video frames.
[0135] The data volume of the first sample video is relatively large, and sometimes the gap between multiple consecutive video frames is small. Therefore, the first sample video can be split into multiple video segments, and multiple video frames are extracted from the multiple video segments to represent the entire first sample video. When performing video amplification, amplification can be performed based on the extracted multiple video frames. For example, the first sample video is split into 25 segments, and video frames are extracted from each video segment, then 25 video frames can be obtained. It should be noted that when each of the multiple first sample videos is split into multiple video segments, the number of video segments split from the multiple first sample videos can be the same, ensuring that a group of first sample videos used to train the first neural network have the same feature dimensions when performing feature extraction, avoiding the problem of calculation errors when the first neural network model performs batch calculations on a group of multiple first sample videos.
[0136] After extracting video frames from the first sample video, when performing video amplification, the amplification can be performed based on the video frames. Therefore, based on the extracted multiple video frames, the first sample video is time-sequentially amplified to obtain a first sub-amplified video, including: time-sequentially amplifying multiple video frames to obtain multiple first sub-amplified video frames.
[0137] The time expansion of multiple video frames can also be performed by deleting some frames or adding some frames. Figure 6 As shown, the first sample video is split into 25 segments, and one frame is extracted from each of the 25 video segments to obtain 25 video frames, namely f1, f2, f3, ..., f25. For these 25 frames, time series expansion can be performed, and some frames can be deleted and some frames can be added. Figure 6 In the example, f2 is deleted and f26 is added after f3, thereby obtaining 25 first sub-amplified video frames corresponding to the time series amplification.
[0138] When performing temporal amplification on a multi-frame video frame, the number of deleted frames and the number of added frames can be the same, so that the number of multi-frame first sub-amplified video frames after temporal amplification is the same as the number of multi-frame video frames, so as to ensure that after feature extraction based on the multi-frame video frame and the multi-frame first sub-amplified video frame, the feature dimensions corresponding to the amplified video features of the two are the same. When calculating the contrastive learning loss using the amplified video features, the problem of calculation errors caused by inconsistent vector dimensions can be avoided.
[0139] Similarly, spatially amplifying the first sample video to obtain a second sub-amplified video includes: spatially amplifying multiple video frames to obtain multiple second sub-amplified video frames. Spatially amplifying multiple video frames may add Gaussian noise to each of the multiple video frames, adjust the contrast, brightness and saturation of each frame, and perform operations such as horizontal flipping, upside down flipping, rotating, cropping or translating on each frame to obtain multiple second sub-amplified video frames.
[0140] Performing spatial amplification on the first sub-amplified video to obtain the third sub-amplified video includes: performing spatial amplification on multiple first sub-amplified video frames obtained by temporal amplification to obtain multiple third sub-amplified video frames. In other words, performing temporal amplification and spatial amplification on multiple video frames simultaneously to obtain multiple third sub-amplified video frames.
[0141] The first sample video is divided into multiple segments and multiple frames are extracted for video amplification, thereby reducing the number of video frames of the first sample video without affecting the video amplification result and improving the efficiency of video amplification.
[0142] In step 420, video features are first extracted from the augmented video based on the first neural network model to obtain augmented video features.
[0143] In one implementation of video amplification in step 410, multiple frames can be extracted from the first sample video frame for time amplification to obtain multiple frames of first sub-amplified video frames, and spatial amplification can be performed to obtain multiple frames of second sub-amplified video frames, and time amplification and spatial amplification can be performed simultaneously to obtain multiple frames of third sub-amplified video frames. Therefore, video feature extraction is performed on the amplified video based on the first neural network model to obtain amplified video features, including: video feature extraction is performed on the multiple frames of amplified video frames based on the first neural network model to obtain amplified video features. The multiple-frame amplified video frames include multiple frames of video frames, multiple frames of first sub-amplified video frames obtained only based on time amplification, multiple frames of second sub-amplified video frames obtained only based on spatial amplification, and multiple frames of third sub-amplified video frames obtained simultaneously based on time amplification and spatial amplification.
[0144] Compared with directly extracting video features from the complete first sample video, extracting video features from multiple augmented video frames can improve feature extraction efficiency.
[0145] In one embodiment, the first neural network model includes a first network layer and a second network layer. Therefore, video feature extraction is performed on multiple augmented video frames based on the first neural network model to obtain augmented video features, including:
[0146] Based on the first network layer, image features are extracted from the multiple augmented video frames to obtain multiple frame features;
[0147] Based on the second network layer, multiple frame features are fused to obtain augmented video features.
[0148] The structure of the first neural network model can be as follows Figure 7 As shown, it includes a first network layer and a second network layer. The first network layer is used for feature extraction, and the second network layer is used for feature fusion.
[0149] The multiple augmented video frames are input into the first network layer of the first neural network model, and the first network layer extracts image features based on each augmented video frame to obtain corresponding frame features. The first network layer can be a multi-layer convolutional neural network, for example, ResNet-50, a convolutional neural network with a depth of 50 layers. The multiple frame features can be obtained by taking the output of the last layer in the first network layer.
[0150] The number of the multiple frame features is the same as the number of the multi-frame augmented video frames, and each augmented video frame corresponds to one frame feature. When the first network layer outputs multiple frame features, a feature matrix of the multiple frame features can be output. For example, the number of the multi-frame augmented video frames is 25, and the dimension of each frame feature extracted by the first network layer is 2048. Therefore, the dimension of the feature matrix composed of the multiple frame features is [25, 2048].
[0151] After obtaining multiple frame features, the multiple frame features can be input into the second network layer. The second network layer is used to perform feature fusion on the multiple frame features to obtain the amplified video features corresponding to the amplified video. The second network layer can be a multi-layer deep learning model, for example, a four-layer transformer model.
[0152] In one implementation, feature fusion is performed on multiple frame features based on the second network layer to obtain augmented video features, including:
[0153] Based on performing linear transformation on the features of the plurality of frames, a first intermediate matrix, a second intermediate matrix and a third intermediate matrix are obtained;
[0154] Normalizing the first intermediate matrix and the transposed matrix of the second intermediate matrix, and multiplying the normalized matrix by the third intermediate matrix to obtain a plurality of frame fusion results;
[0155] Calculate the average value of multiple frame fusion results to obtain the amplified video features.
[0156] The first intermediate matrix, the second intermediate matrix and the third intermediate matrix are all obtained based on the linear transformation of multiple frame features. The process of linearly transforming multiple frame features to obtain the first intermediate matrix can be expressed as Formula 1:
[0157] (Formula 1).
[0158] In formula 1, It can represent the transpose of the feature matrix composed of multiple frame features. represents the linear layer parameters used to calculate the first intermediate matrix, and Q represents the first intermediate matrix.
[0159] The process of linearly changing multiple frame features to obtain the second intermediate matrix can be expressed as Formula 2:
[0160] (Formula 2).
[0161] In formula 2, represents the linear layer parameters used to calculate the second intermediate matrix, and K represents the second intermediate matrix.
[0162] The process of linearly changing multiple frame features to obtain the third intermediate matrix can be expressed as Formula 3:
[0163] (Formula 3).
[0164] In formula 3, represents the linear layer parameters used to calculate the third intermediate matrix, and V represents the third intermediate matrix.
[0165] In Formula 1, Formula 2 and Formula 3, , and are all trainable parameters.
[0166] The process of calculating multiple frame fusion results based on the first intermediate matrix, the second intermediate matrix and the third intermediate matrix can be expressed as Formula 4:
[0167] (Formula 4).
[0168] In formula 4, The first intermediate matrix Q is multiplied by the transpose of the second intermediate matrix K. In order to avoid the multiplication result being too large and causing the normalization result to be inaccurate, the multiplication result can be divided by Then, a normalization process is performed. The result of the normalization process is multiplied by the third intermediate vector V to obtain a plurality of frame fusion results.
[0169] The fusion results of multiple frames can be a feature matrix with the same dimension as the feature matrix composed of multiple frame features. For example, the feature matrix composed of multiple frame features is [25*2048], which represents the frame features of 25 augmented video frames, and the vector dimension of each frame feature is 2048. The feature matrix composed of multiple frame fusion results obtained after feature fusion is also [25*2048], and each row represents the result of fusion of the frame features corresponding to an augmented video frame and the frame features corresponding to other augmented video frames.
[0170] After obtaining multiple frame fusion results corresponding to multiple frames, the average value of the multiple frame fusion results can be calculated to obtain video-level augmented video features. For example, the feature matrix composed of multiple frame fusion results is [25*2048], and the average value of each column is calculated to finally obtain a video-level augmented video feature with a dimension of 2048.
[0171] Based on the above method, feature fusion can eventually obtain an amplified video feature at the video level. Compared with the method of using frame features of multiple frames to represent video features, the first neural network model used in the embodiment of the present disclosure can reduce the amount of features extracted from the video and alleviate the storage pressure of the video features. When comparing the features of videos, it is more efficient to use a video-level video feature for feature comparison, and thus the query efficiency of searching for similar videos from multiple candidate videos is higher.
[0172] The first network layer in the first neural network model is used to extract image features from the augmented video frame, and then the second network layer is used to perform feature fusion to obtain augmented video features, so that after feature extraction at the frame level, multiple frame features are fused together to obtain video-level features. During the feature extraction process, frames do not interfere with each other, so that the information in each frame of the image can be accurately extracted. When performing feature fusion, the video-level features can also fully reflect the information in each frame, thereby improving the accuracy of video-level feature extraction.
[0173] In another implementation of video amplification in step 410 , a plurality of amplified videos are determined according to the first amplified sub-video, the second amplified sub-video, the third amplified sub-video, and the first sample video.
[0174] In another embodiment, extracting video features from the augmented video based on the first neural network model to obtain augmented video features includes:
[0175] Splitting the augmented video into multiple augmented video segments, and extracting multiple video frame images from the multiple augmented video segments;
[0176] Based on the first neural network, frame-level features are extracted from multiple video frame images to obtain augmented video features.
[0177] The difference between this embodiment and the aforementioned embodiment is that the aforementioned embodiment performs frame extraction before video amplification, performs video amplification based on the extracted multiple video frames, and finally performs feature extraction based on the multiple amplified video frames. However, this embodiment performs frame extraction after obtaining the amplified video. The method of extracting multiple video frame images from multiple amplified video segments is the same as the method of splitting the first sample video into multiple video segments and extracting video frames from each video segment in the aforementioned embodiment, and will not be repeated here. The method of performing frame-level feature extraction on multiple video frame images based on the first neural network has also been described in detail in the aforementioned embodiment, and will not be repeated here.
[0178] Extracting frames from the augmented video for video feature extraction can reduce the number of features and improve feature extraction efficiency.
[0179] In addition to extracting video features from the amplified video based on the first neural network model to obtain the amplified video features, step 420 also includes: extracting video features from multiple preset negative sample videos based on the second neural network model to obtain multiple negative sample video features.
[0180] The second neural network model may be a neural network model having the same structure as the first neural network model, and is used to extract video features from a preset negative sample video. Since the preset negative sample video is a video that is different from the first sample video, in order to avoid the preset negative sample video affecting the feature extraction of the first sample video, different neural network models may be used to extract features from the first sample video and the preset negative sample video.
[0181] Since the second neural network model can have the same structure as the first neural network model, the way in which the second neural network model extracts video features from the preset negative sample video is the same as the way in which the first neural network model extracts video features from the amplified video, and no further details are given here. The dimension of the negative sample video features obtained by the second neural network model through video feature extraction is the same as the dimension of the amplified video features. For example, the dimension of the amplified video features corresponding to each amplified video is 2048, and the dimension of the negative sample video features corresponding to the preset negative sample video is also 2048.
[0182] In step 430, a contrastive learning loss is calculated based on the augmented video features and the negative sample video features to obtain a first loss.
[0183] Contrastive learning loss is to learn the representation of data by comparing positive samples with negative samples. The goal of contrastive learning is to make the first neural network model learn a feature space so that similar video features are close in the feature space, while dissimilar video features are far away.
[0184] In one implementation, the contrastive learning loss is calculated based on the augmented video features and the negative sample video features to obtain the first loss, including:
[0185] For each first sample video, randomly select two positive sample pairs from the corresponding multiple amplified video features;
[0186] Calculating a first training similarity between two augmented video features in a positive sample pair;
[0187] Determine a target augmented video feature from two augmented video features in the positive sample pair, and calculate multiple second training similarities between the target augmented video feature and multiple negative sample video features;
[0188] A comparative learning loss is calculated based on the first training similarity and the plurality of second training similarities to obtain a first loss.
[0189] The amplified video includes the first sample video and the video obtained by amplifying the first sample video. That is to say, each first sample video has corresponding multiple amplified videos, and the multiple amplified videos belong to the same video and have extremely high feature similarity. When calculating the contrastive learning loss, two positive sample pairs can be randomly selected from the corresponding multiple amplified video features for each first sample video. The purpose of constructing the positive sample pair is to use the similarity between the two amplified video features in the positive sample pair to allow the first neural network model to learn the distance between the video features of the two videos that are considered to be the same video.
[0190] In one of the aforementioned embodiments, the multiple amplified videos include a first sample video, a first sub-amplified video obtained by temporally amplifying the first sample video, a second sub-amplified video obtained by spatially amplifying the first sample video, and a third sub-amplified video obtained by simultaneously temporally amplifying and spatially amplifying the first sample video. Therefore, the amplified video features include the first sample video features, the first sub-amplified video features, the second sub-amplified video features, and the third sub-amplified video features. Based on this, when constructing a positive sample pair, two can be randomly selected for construction, and there are a total of six combinations of positive sample pairs, namely (first sample video features, first sub-amplified video features), (first sample video features, second sub-amplified video features), (first sample video features, third sub-amplified video features), (first sub-amplified video features, second sub-amplified video features), (first sub-amplified video features, third sub-amplified video features), (second sub-amplified video features, third sub-amplified video features). Although there are multiple ways to construct positive sample pairs based on multiple augmented video features, one of them can be selected to calculate the contrastive learning loss because for a first sample video, the similarity gap between each two augmented video features is small. Therefore, the similarity between multiple augmented video features can be reflected through one positive sample pair.
[0191] After constructing the positive sample pair, the first training similarity between the two augmented video features in the positive sample pair may be calculated, specifically, the calculation may be performed using methods such as Euclidean distance, Manhattan distance, and cosine similarity.
[0192] In order to allow the first neural network model to learn the feature distance between the positive sample and the negative sample, a target augmented video feature can be determined from the two augmented video features in the positive sample pair. The target augmented video feature can be any one of the two augmented video features in the positive sample pair. Calculate multiple second training similarities between the target augmented video feature and multiple negative sample video features. For example, the positive sample pair includes a first sample video feature and a second sub-amplified video feature. The second sub-amplified video feature can be determined as the target augmented video feature, and calculate multiple second training similarities between the second augmented video feature and multiple negative sample video features. The method for calculating the second training similarity is the same as the method for calculating the first training similarity, and needs to be consistent. For example, the first training similarity is calculated using cosine similarity, and the second training similarity also needs to be calculated using cosine similarity to ensure the accuracy of calculating the contrastive learning loss.
[0193] After calculating the first training similarity and the plurality of second training similarities, a contrastive learning loss may be calculated based on the first training similarity and the plurality of second training similarities.
[0194] In one implementation, calculating the contrastive learning loss based on the first training similarity and the plurality of second training similarities to obtain the first loss includes:
[0195] Classifying the target augmented video features based on the first training similarity and the plurality of second training similarities to obtain a predicted category;
[0196] The contrastive learning loss is calculated based on the predicted category and the target category to obtain the first loss.
[0197] The first training similarity can be used to evaluate the similarity between the target augmented video feature and another augmented video feature in the positive sample pair; multiple second training similarities can be used to evaluate the similarity between the target augmented video feature and multiple negative sample video features. When the value of the first training similarity is greater than the values of all the second training similarities, the augmented video corresponding to the target augmented video feature and the augmented video corresponding to another augmented video feature in the positive sample pair can be classified into one category. When there is a second training similarity greater than the first training similarity, the augmented video corresponding to the target augmented video feature and the preset negative sample video corresponding to the negative sample video feature can be classified into one category. Therefore, when classifying the augmented video corresponding to the target augmented video feature, there are two categories, namely positive samples and negative samples, the positive sample is the class where the augmented video belongs, and the negative sample is the class where the preset negative sample video belongs. When the first training similarity is greater than multiple second training similarities, the augmented video corresponding to the target augmented video feature is classified as a positive sample, and when there is a second training similarity greater than the first training similarity, the augmented video corresponding to the target augmented video feature is classified as a negative sample.
[0198] After determining the predicted category corresponding to the target augmented video feature, the contrastive learning loss can be calculated based on the predicted category and the target category. The target category is the real category to which the augmented video corresponding to the target augmented video feature actually belongs, and the known target category is a positive sample.
[0199] The first loss can be expressed as Formula 5 based on the contrastive learning loss calculated based on the predicted category and the target category:
[0200] (Formula 5).
[0201] In formula 5, represents the first loss obtained by calculating the contrastive learning loss of multiple first sample videos; Indicates the target category; represents the predicted category; t represents the sequence number of multiple first sample videos, that is, It represents the contrastive learning loss corresponding to the t-th first sample video. The contrastive learning losses corresponding to a group of multiple first sample videos are summed up to obtain the first loss in a round of training.
[0202] Calculating the contrastive learning loss based on the predicted category and the target category can make the contrastive learning of the first neural network model more rigorous. For each first sample video, a set of positive sample pairs and multiple negative samples are used to predict the category. Only when the similarity between the positive sample pairs is the highest can they be classified into one category, otherwise, they will be classified as negative samples. This requires the first neural network model to achieve extremely high accuracy when extracting features to ensure that the two amplified videos corresponding to the positive sample pairs are classified into one category. Therefore, using the predicted category and the target category to calculate the contrastive learning loss is conducive to improving the accuracy of feature extraction of the first neural network model.
[0203] In step 440 , each first sample video is firstly cropped into multiple sizes in the video frame dimension to obtain multiple cropped videos.
[0204] like Figure 8 As shown in FIG. 1 , 1 / 2, 1 / 4 and 1 / 8 of a first sample video are sequentially cut out as three cutout videos. Figure 8 It can be seen that as the interception size decreases, the same features between the intercepted video and the first sample video become fewer and fewer, and the similarity becomes lower and lower.
[0205] After obtaining the multiple intercepted videos, video features can be extracted from the first sample video and the multiple intercepted videos based on the first neural network model to obtain the first sample video features and the multiple intercepted video features.
[0206] The method of extracting video features using the first neural network model has been described in detail in the previous embodiment and will not be repeated here.
[0207] In step 450, a similarity ranking loss is calculated based on the first sample video feature, the multiple intercepted video features, and the similarity ranking relationship between the multiple intercepted videos and the first sample video to obtain a second loss.
[0208] The similarity ranking loss allows the first neural network model to learn the similarity ranking relationship of features, so that the first neural network model can extract video features with closer distances for more similar videos.
[0209] In one implementation, the similarity ranking loss is calculated based on the first sample video feature, the multiple intercepted video features, and the similarity ranking relationship between the multiple intercepted videos and the first sample video to obtain the second loss, including:
[0210] Combining the first sample video feature with the plurality of intercepted video features in pairs to obtain a plurality of feature comparison groups;
[0211] Calculating a third training similarity between two video features in each feature comparison group;
[0212] A similarity ranking loss is calculated according to the plurality of third training similarities and the similarity ranking relationship between the plurality of intercepted videos and the first sample video to obtain a second loss.
[0213] Multiple feature comparison groups include two video features for similarity comparison. For example, multiple intercepted video features include: 1 / 2 intercepted video features, 1 / 4 intercepted video features and 1 / 8 intercepted video features. Therefore, multiple feature comparison groups are constructed including: (first sample video features, 1 / 2 intercepted video features), (first sample video features, 1 / 4 intercepted video features), (first sample video features, 1 / 8 intercepted video features), (1 / 2 intercepted video features, 1 / 4 intercepted video features), (1 / 2 intercepted video features, 1 / 8 intercepted video features) and (1 / 4 intercepted video features, 1 / 8 intercepted video features).
[0214] For each feature comparison group, the third training similarity between two video features is calculated. The method of calculating the third training similarity can be the same as the method of calculating the first training similarity and the second training similarity in the above embodiment, which will not be repeated here.
[0215] The similarity ranking of multiple captured videos with the first sample video can be that the larger the size of the captured video, the higher the similarity ranking with the first sample video, which is also the goal to be achieved by the third training similarity, that is, the third training similarity between the video features corresponding to videos with similar sizes is higher.
[0216] In order to calculate the similarity ranking loss more intuitively, in one embodiment, the similarity ranking loss is calculated according to the similarity ranking relationship between the plurality of third training similarities and the plurality of intercepted videos and the first sample video to obtain the second loss, including:
[0217] generating a similarity matrix according to a plurality of third training similarities;
[0218] The similarity ranking loss is calculated based on the similarity matrix and the similarity ranking relationship between the multiple intercepted videos and the first sample video to obtain a second loss.
[0219] The similarity matrix can intuitively represent the relationship between the intercepted video features of each size and the first sample video features. The number of rows and columns of the similarity matrix is equal to the sum of the number of the first sample video features and the intercepted video features. Each row and column represents a video feature, and each matrix value represents the third training similarity between the two video features at the corresponding position.
[0220] For example Figure 8 In the similarity matrix shown in FIG. 1 , in addition to the first sample video feature, there are 3 intercepted video features, namely 1 / 2 intercepted video feature, 1 / 4 intercepted video feature and 1 / 8 intercepted video feature. Therefore, the similarity matrix is a matrix with 4 rows and 4 columns. In the row dimension, they are arranged from top to bottom in the order of video size from large to small, and in the column dimension, they are arranged from left to right in the order of video size from large to small, namely the first sample video feature, 1 / 2 intercepted video feature, 1 / 4 intercepted video feature and 1 / 8 intercepted video feature. When the number of rows and columns in the similarity matrix is equal, it indicates the similarity between the video feature at the corresponding position and itself. Since the video features are exactly the same, the similarity is the largest and is 1. The first column of the second row indicates the third training similarity (0.82) between the 1 / 2 intercepted video feature and the first sample video feature; the second column of the third row indicates the third training similarity (0.75) between the 1 / 2 intercepted video feature and the 1 / 4 intercepted video feature.
[0221] The similarity ranking relationship between the multiple intercepted videos and the first sample video should be that the closer the size, the higher the similarity ranking. For example, the similarity between the first sample video feature and the 1 / 2 intercepted video feature is higher than the similarity between the first sample video feature and the 1 / 4 intercepted video feature; the similarity between the 1 / 2 intercepted video feature and the 1 / 8 intercepted video feature is higher. Therefore, when calculating the similarity ranking loss based on the similarity matrix and the similarity ranking relationship between the multiple intercepted videos and the first sample video, the calculation can be performed based on the similarity ranking in the similarity matrix.
[0222] In one embodiment, the similarity ranking loss is calculated based on the similarity matrix and the similarity ranking relationship between the plurality of intercepted videos and the first sample video to obtain the second loss, including:
[0223] For each column in the similarity matrix, the matrix value whose corresponding row number is greater than or equal to the corresponding column number is determined as the target matrix value, and the matrix value whose corresponding row number is greater than the corresponding row number of the target matrix value is determined as the comparison matrix value of the target matrix value;
[0224] Calculate the difference between the comparison matrix value and the corresponding target matrix value to obtain the ranking difference;
[0225] The similarity ranking loss is calculated based on the ranking difference to obtain the second loss.
[0226] Since the similarity matrix is a symmetric matrix, the values of the upper right half and the lower left half are the same, so when calculating the similarity ranking loss, you can only calculate the lower left half or the upper right half of the similarity matrix. When calculating based on the lower left half of the similarity matrix, calculate the matrix values whose row number is greater than or equal to the column number, for example, the 2nd row and the 1st column, or the 3rd row and the 2nd column.
[0227] In the lower left part of the similarity matrix, for each column in the similarity matrix, based on the similarity ranking relationship between the multiple intercepted videos and the first sample video, it can be seen that the larger the number of rows, the smaller the matrix value. Fig. 9 The matrix values of the first column and the first row (similarity comparison of the first sample video feature itself) should be greater than the matrix values of the second, third and fourth rows; the matrix value of the second row (the third training similarity between the first sample video feature and the 1 / 2 intercepted video feature) should be greater than the matrix values of the third and fourth rows. Therefore, each matrix value in the lower left half is used as the target matrix value, and the matrix value in the column where the target matrix value is located and whose row number is greater than the target matrix value row number is used as the comparison matrix value. The difference between the comparison matrix value and the target matrix value is calculated to determine whether the goal of smaller matrix values in the same column with larger row numbers is met. For example, in Fig. 9 In the first column of , the matrix value in the second row is used as the target matrix value, then its corresponding comparison matrix value includes the matrix value in the first row and third column and the matrix value in the first row and fourth column.
[0228] The ranking difference is obtained by calculating the difference between the comparison matrix value and the target matrix value. When the ranking difference is greater than 0, it means that the comparison matrix value is greater than the target matrix value, which does not meet the goal that the larger the row number in the same column, the smaller the matrix value; when the ranking difference is less than 0, it means that the comparison matrix value is less than the target matrix value, which meets the goal that the larger the row number in the same column, the smaller the matrix value. When the comparison matrix value and the target matrix value can meet the goal, the ranking difference can be adjusted to 0, indicating that there is no similarity ranking loss between this comparison matrix value and the target matrix value; conversely, when the goal is not met, the ranking difference can be used as the similarity ranking loss between this comparison matrix value and the target matrix value.
[0229] By adding the similarity ranking losses generated between multiple target matrix values and corresponding comparison matrix values in the similarity matrix, the similarity ranking losses generated between the first sample video and the corresponding multiple intercepted videos in one round of training can be obtained.
[0230] The process of calculating the second loss using the similarity matrix in the above implementation can be expressed as Formula 6:
[0231] (Formula 6).
[0232] In Formula 6, represents the second loss; i represents the column number in the similarity matrix; j represents the row number in the similarity matrix;
[0233] Represents the target matrix value of the i-th column and j-th row; Indicates the comparison matrix value of the i-th column and the j+1-th row corresponding to the target matrix value;
[0234] m represents the marginal coefficient. When the target matrix value is equal to the comparison matrix value, the ranking difference is 0. However, it does not meet the goal that the larger the row number in the same column, the smaller the matrix value. Therefore, the marginal coefficient can be used to increase the ranking difference.
[0235] Indicates that when the comparison matrix value is greater than or equal to the target matrix value, the ranking difference is equal to , otherwise, the sorting difference is equal to 0;
[0236] Indicates that the ranking difference is calculated for the lower left half (i<=j) of the similarity matrix to calculate the similarity ranking loss between the first sample video and the corresponding multiple intercepted videos;
[0237] t represents the sequence numbers of the plurality of first sample videos, and based on the sum of the similarity ranking losses of the plurality of first sample videos and the corresponding plurality of intercepted videos, a second loss for one round of training using the plurality of first sample videos can be obtained;
[0238] N represents the number of similarity matrices in a round of training, that is, the number of first sample videos. Since the total similarity ranking loss obtained by adding the similarity ranking losses of multiple first sample videos and the corresponding multiple intercepted videos is large, it may cause the training of the first neural network model to be too biased towards similarity ranking. Therefore, the sum of the similarity ranking losses corresponding to the multiple first sample videos can be multiplied by The coefficient of , and finally the second loss is obtained.
[0239] Using the similarity matrix to calculate the similarity ranking loss can intuitively and accurately obtain the similarity ranking relationship between multiple intercepted videos and the first sample video, and calculate the similarity ranking loss between the matrix values based on the similarity ranking relationship, which is conducive to improving the efficiency and accuracy of calculating the similarity ranking loss.
[0240] In another embodiment, the training process of the first neural network model further includes:
[0241] Obtaining multiple second sample videos and a classification label corresponding to each second sample video;
[0242] Extracting video features from the second sample video based on the first neural network model to obtain second sample video features;
[0243] Classify the second sample video features based on a preset classification network layer to obtain a classification prediction probability value;
[0244] The classification loss is calculated based on the classification prediction probability value and the classification label to obtain the third loss.
[0245] The multiple second sample videos are video samples carrying classification labels. The multiple second sample videos may have intersections with the multiple first video samples, or may be sample videos completely different from the multiple first sample videos. The multiple second sample videos can be obtained by obtaining videos carrying classification labels from public video data websites, such as the MovieNet classification dataset, which contains multiple types of video data. Specifically, videos can be classified according to video scenes, emotional atmospheres, action types, style types, video themes, and release years. Videos carrying classification labels can also be obtained from multiple video recommendation applications. The classification label indicates the video category to which the second sample video belongs, such as comedy, horror, etc.
[0246] The process of extracting video features based on the first neural network model has been described in detail in the above embodiments and will not be repeated here.
[0247] After extracting the second sample video features, the second sample video features can be classified using a preset classification network layer to obtain a classification prediction probability value. The classification prediction probability value can represent the probability that the second sample video is predicted to be classified into a class corresponding to the classification label. The second sample video features can be classified according to the classification prediction probability value to obtain a predicted category. The preset classification network layer can be a multi-layer deep neural network, for example, a CNN network or a Transformer model.
[0248] The classification loss can be calculated based on the classification prediction probability value and the classification label. The process of calculating the classification loss can be expressed as Formula 7:
[0249] (Formula 7).
[0250] In Formula 7, represents the classification label corresponding to the d-th second sample video, represents the predicted category based on the classification prediction probability value, so, Denotes the classification loss corresponding to the d-th second sample video. According to the sum of the classification losses corresponding to multiple second sample videos, the third loss of multiple second sample videos in one round of training can be obtained.
[0251] Adding classification loss during the training process of the first neural network model allows the first neural network model to learn feature associations between videos of the same category, thereby further improving the feature extraction accuracy of the first neural network model.
[0252] In step 460, the parameters of the first neural network model are updated according to the first loss and the second loss.
[0253] After calculating the first loss and the second loss, the first loss and the second loss can be added to obtain the total loss, and the total loss can be used to update the parameters of the first neural network model. For example, if the first loss is 5 and the second loss is 6, then the total loss is 11.
[0254] The calculation of the total loss can also assign different weight parameters to the first loss and the second loss, and calculate the weighted sum between the first loss and the second loss based on the weight parameters to obtain the total loss. The weight parameter indicates the impact of the first loss and the second loss on the training of the first neural network model. Since the first loss trains the first neural network model's feature extraction ability to distinguish between duplicate videos and similar videos, the second loss trains the first neural network model's ability to sort the similarities of multiple similar videos. Therefore, different weight parameters can be assigned to the first loss and the second loss based on the training bias of the first neural network model in actual applications. For example, the first loss is 5, the second loss is 6, the weight parameter corresponding to the first loss is 1.2, and the weight parameter corresponding to the second loss is 0.8, then the total loss is 5*1.2+6*0.8=10.8.
[0255] The parameters of the first neural network model are updated using the total loss. The gradient of the total loss relative to the parameters of the first neural network model can be calculated through a back-propagation algorithm. After calculating the gradient, an optimization algorithm (such as a stochastic gradient descent algorithm) is used to update the parameters of the first neural network in the direction of gradient descent.
[0256] In the aforementioned embodiment, in addition to the first loss and the second loss, a third loss is calculated based on a plurality of second sample videos carrying labels. Based on this, the parameters of the first neural network model are updated according to the first loss and the second loss, including: updating the parameters of the first neural network model according to the first loss, the second loss and the third loss.
[0257] In the same way as updating the parameters of the first neural network model according to the first loss and the second loss, the first loss, the second loss and the third loss can be added to obtain the total loss, and the parameters of the first neural network model can be updated using the total loss. Specifically, it can be expressed as Formula 8:
[0258] (Formula 8).
[0259] In formula 8, represents the total loss, represents the first loss, represents the second loss, Indicates the third loss.
[0260] The total loss can also be calculated by assigning different weight parameters to the first loss, the second loss, and the third loss, and using the weight parameters to calculate the weighted sum of the first loss, the second loss, and the third loss to obtain the total loss. Specifically, it can be expressed as Formula 9:
[0261] (Formula 9).
[0262] In Formula 9, represents the weight parameter corresponding to the first loss, represents the weight parameter corresponding to the second loss, Represents the weight parameter corresponding to the third loss.
[0263] The process of updating the parameters of the first neural network based on the total loss has been described in detail in the aforementioned embodiment and will not be repeated here.
[0264] In one implementation, after updating the parameters of the first neural network model according to the first loss and the second loss, the training process of the first neural network model further includes:
[0265] Get the momentum update coefficients of the model parameters;
[0266] The parameters of the second neural network model are updated based on the updated parameters of the first neural network model and the momentum update coefficient.
[0267] After updating the first neural network model, the parameters of the second neural network model can also be updated according to the parameters of the first neural network model, so that the second neural network model can achieve a more accurate extraction effect when performing feature extraction on the preset negative sample video, thereby improving the accuracy of using negative sample videos to assist in training the first neural network model.
[0268] The second neural network model has the same network result as the first neural network model, so the second neural network model can be momentum updated based on the update of the parameters in the first neural network model. The momentum update can be updated based on the previous gradient update direction of the second neural network model and the gradient update method in the first neural network model.
[0269] The momentum update coefficient can indicate the update degree of the parameters in the second neural network model. The larger the momentum update coefficient, the greater the influence of the previous gradient update direction of the second neural network model on the current gradient update. After experimental verification, when the momentum update coefficient is 0.99, a better momentum update effect can be obtained.
[0270] The updating of the parameters of the second neural network model based on the updated parameters of the first neural network model and the momentum update coefficient can be expressed as Formula 10:
[0271] (Formula 10).
[0272] In formula 10, represents the parameters of the second neural network before updating; Represents the updated parameters of the second neural network model; represents the updated parameters of the first neural network model; e represents the momentum update coefficient. The momentum update coefficient can be used as a weight to control the influence of the gradient update direction of the first neural network model and the previous gradient update direction of the second neural network model on the gradient update of the current second neural network model.
[0273] Updating the parameters in the second neural network model based on momentum update can make the second neural network model converge quickly to achieve the fastest and best feature extraction effect. The negative sample video features obtained based on the second neural network model are becoming more and more accurate, which can accelerate the training of the first neural network model.
[0274] Using the first neural network model to extract video features from the amplified video, and using the second neural network to extract video features from the preset negative sample video, can avoid the influence of the feature extraction of the negative sample video on the feature extraction of the amplified video, which is beneficial to improving the accuracy of the training of the first neural network model. Training the first neural network model based on the comparative learning loss of the amplified video features and the negative sample video features can enable the first neural network model to have the ability to distinguish between duplicate videos and similar videos when performing feature extraction; training the first neural network model based on the similarity ranking loss between multiple intercepted videos and the first sample video can enable the first neural network model to have the ability to extract video features of different distances based on the similarity ranking between the videos, and for videos with higher similarity, video features of closer distances can be extracted. Therefore, the training process of the first neural network model proposed in the embodiment of the present disclosure is beneficial to improving the accuracy of the first neural network model in video feature extraction.
[0275] After the first neural network model is trained, the first neural network model can be used to extract video features from a query video and multiple candidate videos.
[0276] In one of the aforementioned implementations, the first neural network model includes a first network layer and a second network layer. Based on this, video features are extracted from the query video and multiple candidate videos based on the first neural network model to obtain query video features and multiple candidate video features, including:
[0277] Extracting multiple query video frames from the query video, and extracting multiple candidate video frames from each candidate video;
[0278] Extracting image features from multiple query video frames based on the first network layer to obtain multiple query frame features, and extracting image features from multiple candidate video frames based on the first network layer to obtain multiple candidate frame features;
[0279] Based on the second network layer, feature fusion is performed on multiple query frame features to obtain query video features, and based on the second network layer, feature fusion is performed on multiple candidate frame features corresponding to each candidate video to obtain multiple candidate video features.
[0280] When extracting features from a query video and multiple candidate videos, multiple frames may be extracted from the query video and the candidate videos, and video-level features may be obtained by processing frame-level features.
[0281] In one embodiment, extracting multiple query video frames from the query video, and extracting multiple candidate video frames from each candidate video, includes:
[0282] Splitting the query video into a plurality of query video segments, and splitting each candidate video into a plurality of candidate video segments;
[0283] Extracting a query video frame from each query video segment to obtain multiple query video frames;
[0284] A candidate video frame is extracted from each candidate video segment to obtain multiple candidate video frames corresponding to each candidate video.
[0285] The same method as extracting frames from the first sample video in the aforementioned embodiment is to first split the query video into multiple query video segments, extract one frame from each query video segment, and thus obtain multiple query video frames. Split the candidate video into multiple candidate video segments, extract one frame from each candidate video segment, and thus obtain multiple candidate video frames. The query video and the candidate video can be split into the same number of segments, for example, if both the query video and the candidate video are split into 25 segments, then 25 query video frames and 25 candidate video frames can be extracted.
[0286] Since the similarity between several consecutive frames of a video is high, splitting the query video and the candidate video into multiple segments and extracting frames from each segment can make the extracted multiple frames different, and the extracted multiple frames come from multiple time segments of the entire video, which can improve the accuracy of generating video-level features based on frame-level feature fusion.
[0287] After extracting multiple query video frames and multiple candidate video frames, image feature extraction can be performed on the multiple query video frames based on the first network layer, and image feature extraction can be performed on the multiple candidate video frames. The process of image feature extraction by the first network layer has been described in detail in the training process of the first neural network model mentioned above, and will not be repeated here.
[0288] The second network layer can perform feature fusion on multiple query frame features to obtain query video features, and perform feature fusion on multiple candidate frame features corresponding to each candidate video to obtain multiple candidate video features. The process of multi-frame feature fusion by the second network layer has been described in detail in the training process of the first neural network model mentioned above, and will not be repeated here.
[0289] Multiple frames are extracted from the query video and the candidate videos, and the frame image features are first extracted using the first network layer. Then, the multiple frame image features are fused using the second network layer to obtain video-level video features, which is beneficial to improving the accuracy of video features obtained by fusion based on frame features.
[0290] Step 330: Calculate the similarity between the query video feature and each candidate video feature.
[0291] In step 330, similar to the process of calculating the first training similarity in the training process of the aforementioned first neural network model, the similarity between the query video feature and each candidate video feature can be calculated by using methods such as Euclidean distance, Manhattan distance and cosine similarity, which will not be repeated here.
[0292] Step 340: Recommend videos based on similarity.
[0293] The greater the similarity, the closer the candidate video is to the query video. Therefore, video recommendation based on similarity can recommend candidate videos to the object in descending order of similarity.
[0294] In another embodiment, recommending videos based on similarity includes:
[0295] Determine a video among multiple candidate videos whose similarity to the query video is less than a preset threshold as a first target video;
[0296] Sorting the plurality of first target videos in descending order according to the similarity with the query video, and determining a preset number of videos ranked first as second target videos;
[0297] Recommending multiple second target videos to the recommendation object.
[0298] Since multiple candidate videos may contain videos that repeat the query video content, recommending these duplicate videos to the object will affect the object's perception. Therefore, a preset threshold can be used to determine whether the candidate video is duplicated with the query video. For example, the preset threshold is 0.92. When the similarity between the candidate video and the query video is greater than 0.92, the candidate video is a video that repeats the query video. Based on this, the candidate video whose similarity with the query video is less than the preset threshold can be used as the first target video, and the video recommended to the recommended object is determined from the first target video.
[0299] When recommending videos to a recommendation object, videos with high similarity can be recommended first. Therefore, the first target videos can be sorted in descending order according to the similarity with the query video. Because, when the similarity is too low, the first target video is not suitable for recommendation to the recommendation object. Therefore, a preset number of first target videos ranked first can be recommended to the recommendation object as second target videos, and the candidate videos ranked in the candidate can be not recommended due to their low similarity.
[0300] By screening candidate videos based on a preset threshold and recommending them, videos that are duplicated with the query video can be removed from multiple candidate videos, and the remaining candidate videos can be sorted according to similarity before recommending the first predetermined number of videos to the object, thereby avoiding recommending irrelevant videos with low similarity to the query video to the object. Therefore, the above implementation method of video recommendation can improve the accuracy of video recommendation.
[0301] Through the above process, the video recommendation method provided by the embodiment of the present disclosure can generate obvious feature distinctions for duplicate videos of the query video and similar videos of different similarities in multiple candidate videos when extracting video features from the query video and multiple candidate videos. The video features of the query video have the highest similarity with the video features of the duplicate video; for other similar videos, the higher the similarity, the higher the similarity between the video features. In this way, the duplicate videos of the query video have a large difference in similarity with other similar videos. When recommending videos, duplicate videos can be accurately removed, and for multiple similar videos, they can be recommended according to the similarity sorting. Therefore, the video recommendation method provided by the embodiment of the present disclosure can avoid recommending duplicate videos to the object, and can recommend videos according to the similarity sorting, thereby improving the accuracy of video recommendation. In addition, in the video recommendation method provided by the embodiment of the present disclosure, the training process of the first neural network model does not require the participation of video samples carrying classification labels, thereby reducing the consumption of computing resources and the occupation of content space, and improving the efficiency of model training.
[0302] like Fig.10 FIG. 1 is another flow chart of the video recommendation method provided by the present disclosure. The method specifically comprises the following steps:
[0303] Step 1010: Obtain a query video and multiple candidate videos.
[0304] The query video is the video content that the subject is interested in in the video recommendation application. The query video can be obtained based on the subject's operation in the video recommendation application. For example, if the subject likes or comments on a certain video content, it can be said that the subject is interested in this video content. Therefore, other video content similar to this video content can be found for recommendation.
[0305] Multiple candidate videos are videos that can be recommended to the subject, and can be obtained from the video library in the background of the video recommendation application. The purpose of video recommendation is to find candidate videos similar to the query video from multiple candidate videos and recommend them to the subject. If the subject is interested in the query video, then there is a high probability that the subject will also be interested in candidate videos that are highly similar to the query video.
[0306] Step 1020: extract multiple query video frames from the query video, and extract multiple candidate video frames from each candidate video.
[0307] Extracting multiple query video frames from the query video can be performed by splitting the query video into multiple query video segments, extracting one query video frame from each query video segment, and obtaining multiple query video frames. For example, the query video is evenly split into 25 segments, and one frame is extracted from each segment to obtain 25 query video frames.
[0308] Similarly, extracting multiple candidate video frames from the candidate video can split each candidate video into multiple candidate video segments, extracting one candidate video frame from each candidate video segment, and obtaining multiple candidate video frames corresponding to each candidate video. The number of splits of the query video and the candidate video can be the same.
[0309] Step 1030: utilize the first network layer in the first neural network model to perform image feature extraction on multiple query video frames to obtain multi-frame query frame features, and perform image feature extraction on multiple candidate video frames to obtain multi-frame candidate frame features; utilize the second network layer to perform feature fusion on multiple query frame features to obtain query video features, and perform feature fusion on multiple candidate video frames to obtain candidate video features.
[0310] The first neural network model can be used to extract features from the video. Specifically, the feature extraction process of the first neural network model can be defined as Formula 11:
[0311] (Formula 11).
[0312] In Formula 11, P represents the first neural network model, x represents multiple frames of images corresponding to the video input into the first neural network model, and F represents the video features obtained by feature extraction by the first neural network.
[0313] The first network layer in the first neural network model is used to extract image features of frames; the second network layer is used to fuse the frame features extracted from multiple frames to obtain video features. The first network layer can use ResNet50 for feature extraction, and the second network layer can use a four-layer transformer model for feature fusion.
[0314] The training process of the first neural network model is as follows Fig.11As shown, the following is combined with steps 1031-1039 Fig.11 Provide explanation.
[0315] Step 1031, obtain multiple first sample videos and multiple preset negative sample videos, split the first sample video into multiple video segments, and extract video frames from each video segment to obtain multiple video frames; perform time amplification and spatial amplification on the multiple video frames to obtain multiple amplified video frames.
[0316] The first sample video is a video sample used to train the first neural network model, and multiple first sample videos can constitute a training set. The first sample video can be obtained from a public video database or from multiple video recommendation applications. The preset negative sample video can be a video that is different in content from the first sample video, and is used to assist the first sample video in training the first neural network model. Multiple preset negative sample videos can be obtained from a negative sample video library. The negative sample video library can be a video library containing 500,000 preset negative sample videos. During training, 63,355 preset negative sample videos can be extracted from the negative sample video library to assist the first neural network model in training, so that the first neural network model can learn a large number of negative sample video features, thereby improving the generalization of the model.
[0317] The first sample video is split into a plurality of video segments, and a plurality of video frames are extracted from the plurality of video segments to represent the entire first sample video. Specifically, the first sample video can be split into 25 segments, and 25 video frames are extracted therefrom.
[0318] When performing video amplification, time amplification and spatial amplification can be performed on multiple video frames. The methods of time amplification include: deleting certain frames, adding certain frames, etc.; spatial amplification includes adding Gaussian noise, modifying contrast, brightness and saturation hue, etc.; horizontally flipping, upside down flipping, rotating cropping or translating the frame image, etc. When performing time amplification and spatial amplification on multiple video frames, only time amplification or only spatial amplification can be performed, or both time amplification and spatial amplification can be performed.
[0319] The multi-frame augmented video frames include multi-frame video frames extracted from the first sample video, multi-frame video frames only subjected to temporal augmentation, multi-frame video frames only subjected to spatial augmentation, and multi-frame video frames subjected to both temporal augmentation and spatial augmentation.
[0320] Step 1032: based on the first network layer in the first neural network model, perform feature extraction on multiple frames of augmented video frames to obtain multiple frame features; based on the second network layer, perform feature fusion on multiple frame features to obtain augmented video features; based on the second neural network model, perform video feature extraction on multiple preset negative sample videos to obtain multiple negative sample video features.
[0321] The first network layer can use ResNet50 to extract frame image features, and take the output of the last layer as multiple frame features. The second network layer can perform feature fusion on multiple frame features to obtain video-level amplified video features. The process of feature fusion in the second network layer is shown in Formula 1-Formula 4 in the aforementioned embodiment. The multi-head attention mechanism is used to linearize the feature vector composed of multiple frame features through a linear layer, and then the frame-level fusion result is obtained based on the linearization result. The features in the frame-level fusion result are averaged to obtain video-level amplified video features.
[0322] The second neural network model may be a neural network model having the same structure as the first neural network model, and is used to extract video features from a preset negative sample video. Since the second neural network model may have the same structure as the first neural network model, the second neural network model extracts video features from the preset negative sample video in the same manner as the first neural network model extracts video features from the augmented video.
[0323] Step 1033: Calculate the comparative learning loss based on the amplified video features and the negative sample video features to obtain a first loss.
[0324] The augmented video features include video features corresponding to multiple augmented videos. When calculating the contrastive learning loss, two augmented video features corresponding to multiple augmented videos can be randomly selected to form a positive sample pair, a target augmented video feature can be determined from the two augmented video features in the positive sample pair, and the target augmented video feature and each negative sample video feature can be combined to form a negative sample pair.
[0325] The similarity between the two video features in the positive sample pair is calculated using methods such as Euclidean distance or cosine similarity; the similarity between the two video features in the negative sample pair is calculated. The target augmented video features are classified according to the similarity corresponding to the positive sample pair and the similarity corresponding to multiple negative sample pairs. When the similarity of the positive sample pair is greater than the similarity of all negative sample pairs, the target augmented video feature can be classified as a positive sample; conversely, when there is a negative sample pair whose similarity is greater than the similarity of the positive sample pair, the target augmented video feature can be classified as a negative sample. Since it is known that the target augmented video feature belongs to the positive sample, the positive sample can be used as the true label, and the contrastive learning loss can be calculated based on the classification result of the target augmented video feature. The specific calculation process is shown in Formula 5 in the aforementioned implementation. The first loss generated by a round of training can be obtained by adding the contrastive learning losses corresponding to multiple first sample videos in a round of training.
[0326] Step 1034: crop each first sample video in multiple sizes on the video frame dimension to obtain multiple cropped videos, and extract video features from the first sample video and the multiple cropped videos based on the first neural network model to obtain first sample video features and multiple cropped video features.
[0327] The first sample video can be intercepted in multiple sizes on the frame dimension to obtain videos of three sizes: 1 / 2, 1 / 4 and 1 / 8. As the interception size decreases, the same features between the intercepted video and the first sample video become fewer and fewer, and the similarity becomes lower and lower.
[0328] After obtaining multiple intercepted videos, the first sample video and the multiple intercepted videos may be input into a first neural network for feature extraction to obtain features of the first sample video and features of the multiple intercepted videos.
[0329] Step 1035: Calculate the similarity ranking loss based on the first sample video feature, the multiple intercepted video features, and the similarity ranking relationship between the multiple intercepted videos and the first sample video to obtain a second loss.
[0330] When calculating the second loss, the similarity between the first sample video feature and the multiple intercepted video features can be calculated, and a similarity matrix can be constructed based on the similarity. The similarity matrix can intuitively represent the relationship between the intercepted video features of various sizes and the first sample video features. The number of rows and columns of the similarity matrix are equal to the sum of the number of the first sample video features and the intercepted video features. Each row and column represents a video feature, and each matrix value represents the similarity between the two video features at the corresponding positions. Based on the similarity ranking relationship between the multiple intercepted videos and the first sample video, it can be seen that the similarity in the similarity matrix should satisfy the same column. The larger the row number, the smaller the matrix value.
[0331] When calculating the similarity ranking loss based on the similarity matrix and the similarity ranking relationship between the multiple intercepted videos and the first sample video, it can be as shown in Formula 6. Take each matrix value in the lower left half as the target matrix value, and take the matrix value whose row number in the column where the target matrix value is located is greater than the row number of the target matrix value as the comparison matrix value. Determine whether the goal of the larger the row number in the same column, the smaller the matrix value is met by calculating the difference between the comparison matrix value and the target matrix value. The ranking difference is obtained by calculating the difference between the comparison matrix value and the target matrix value. When the ranking difference is greater than 0, it means that the comparison matrix value is greater than the target matrix value, and the goal of the larger the row number in the same column, the smaller the matrix value is not met; when the ranking difference is less than 0, it means that the comparison matrix value is less than the target matrix value, and the goal of the larger the row number in the same column, the smaller the matrix value is met. When the comparison matrix value and the target matrix value can meet the goal, the ranking difference can be adjusted to 0, indicating that there is no similarity ranking loss between this comparison matrix value and the target matrix value; conversely, when the goal is not met, the ranking difference can be used as the similarity ranking loss between this comparison matrix value and the target matrix value. The similarity ranking losses generated between multiple target matrix values and corresponding comparison matrix values in the similarity matrix are added to obtain the similarity ranking losses generated between the first sample video and the corresponding multiple intercepted videos in one round of training. The second loss generated in one round of training can be obtained by adding the similarity ranking losses corresponding to multiple first sample videos in one round of training.
[0332] Step 1036 obtains the second sample video and the corresponding classification label, extracts video features of the second sample video based on the first neural network model to obtain second sample video features, and classifies the second sample video features based on a preset classification network to obtain a classification prediction probability value.
[0333] The multiple second sample videos are video samples carrying assigned labels. The multiple second sample videos may have an intersection with the multiple first sample videos, or may be sample videos different from the multiple first sample videos. The multiple second sample videos can be obtained by obtaining videos carrying classification labels on a public video data website, such as the MovieNet classification dataset, which contains multiple types of video data. Specifically, videos can be classified according to video scenes, emotional atmospheres, action types, style types, video themes, and release years. The classification label indicates the video category to which the second sample video belongs, such as comedy, horror, etc.
[0334] After extracting video features from the second sample video based on the first neural network model, the second sample video features are obtained, and the second sample video features are classified based on the preset classification network to obtain a classification prediction probability value. The preset classification network layer can be a multi-layer deep neural network, for example, a CNN network or a Transformer model. The classification prediction probability value can represent the probability that the second sample video is predicted to be classified as a classification label.
[0335] Step 1037: Calculate the classification loss based on the classification prediction probability value and the classification label to obtain a third loss.
[0336] The classification loss calculated based on the classification prediction probability value and the classification label can be expressed as Formula 7. The classification loss is calculated by using the classification label of the second sample video itself to obtain the third loss.
[0337] The third loss generated by a round of training can be obtained by adding up the classification losses corresponding to multiple second sample videos in a round of training.
[0338] Step 1038: Update the parameters of the first neural network model according to the first loss, the second loss, and the third loss.
[0339] When the parameters of the first neural network model are updated according to the first loss, the second loss and the third loss, the first loss, the second loss and the third loss can be added to obtain the total loss. The gradient of the total loss relative to the parameters of the first neural network model is calculated using the back propagation algorithm, and then the parameters of the first neural network are updated in the direction of gradient descent using the optimization algorithm.
[0340] Step 1039: Update the parameters in the second neural network model based on the updated parameters of the first neural network model and the momentum update coefficient.
[0341] After updating the first neural network model, the parameters of the second neural network model can also be updated according to the parameters of the first neural network model. The second neural network model has the same network structure as the first neural network model, so the second neural network model can be momentum updated based on the update of the parameters in the first neural network model. The momentum update can be updated based on the previous gradient update direction of the second neural network model and the gradient update method in the first neural network model. The momentum update coefficient can indicate the degree of update of the parameters in the second neural network model. The larger the momentum update coefficient, the greater the influence of the previous gradient update direction of the second neural network model on the current gradient update. The momentum update coefficient can be taken as 0.99.
[0342] Updating the parameters in the second neural network model based on the updated parameters of the first neural network model and the momentum update coefficient can be expressed as Formula 10 in the aforementioned embodiment. Every time the parameters in the first neural network model are updated, the parameters in the second neural network model are synchronously updated.
[0343] Step 1040: Calculate the similarity between the query video feature and the candidate video feature corresponding to each candidate video.
[0344] The similarity between the query video feature and the candidate video feature corresponding to each candidate video is calculated using methods such as Euclidean distance, Manhattan distance and cosine similarity.
[0345] Step 1050: Determine candidate videos whose similarity to the query video is less than a preset threshold as candidate recommendation videos, sort the candidate recommendation videos in descending order of similarity to the query video, and recommend a predetermined number of videos ranked first to the object.
[0346] The preset threshold can be used to determine whether the candidate video is repeated with the query video. The preset threshold can be 0.92. When the similarity between the candidate video and the query video is greater than 0.92, the candidate video is a video that is repeated with the query video. The candidate video that is repeated with the query video should not be recommended to the object again. Therefore, the candidate video whose similarity with the query video is less than the preset threshold is determined as a candidate recommendation video.
[0347] When recommending videos to an object, the ones with high similarity can be recommended first. Therefore, multiple candidate recommended videos can be sorted in descending order according to the similarity with the query video. When the similarity between the candidate recommended video and the query video is too low, it should not be recommended to the object, which may be a video that the object is not interested in. Therefore, a predetermined number of videos ranked first can be recommended to the object to ensure that the candidate videos recommended to the object are all highly similar to the query video.
[0348] The video recommendation method of the embodiment of the present disclosure can accurately and efficiently compare videos and find similar videos. Through experimental comparisons in multiple scenarios, the accuracy of video recommendation in the embodiment of the present disclosure is significantly higher than that of the video recommendation method in the related art. As shown in Table 1:
[0349]
[0350] Table 1
[0351] In scenario 1, compared with the related art, the recommendation accuracy of the embodiment of the present disclosure is improved from 0.345 to 0.430; in scenario 2, the recommendation accuracy of the embodiment of the present disclosure is improved from 0.367 to 0.443. The normalized loss cumulative gain is used to evaluate whether the similarity ranking of multiple candidate videos and the query video is reasonable. The larger the normalized loss cumulative gain, the more reasonable the ranking and the more accurate the recommendation result. Based on this, the video recommendation method of the embodiment of the present disclosure can effectively improve the accuracy of video recommendation.
[0352] It is to be understood that, although the steps in the above-mentioned flowcharts are sequentially displayed according to the characterization of arrows, these steps are not necessarily executed in sequence according to the order of arrow characterization. Unless there is a clear description in the present embodiment, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the above-mentioned flowcharts can 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 to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the steps or stages in other steps.
[0353] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to the characteristics of the target content such as target content attribute information or attribute information sets, the permission or consent of the target content will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. In addition, when the embodiment of the present application needs to obtain the attribute information of the target content, it will obtain the separate permission or separate consent of the target content through a pop-up window or jump to a confirmation page. After clearly obtaining the separate permission or separate consent of the target content, the necessary target content-related data used to enable the normal operation of the embodiment of the present application will be obtained.
[0354] Fig.12 The structure diagram of the video recommendation device 1200 provided in the embodiment of the present disclosure is shown in FIG. The video recommendation device 1200 includes:
[0355] An acquisition unit 1210 is used to acquire a query video and a candidate video library, where the candidate video library includes multiple candidate videos;
[0356] The feature extraction unit 1220 is used to extract video features of the query video and multiple candidate videos based on the first neural network model to obtain query video features and multiple candidate video features. The first neural network model is obtained based on target loss training. The target loss includes a first loss and a second loss. The first loss is a comparative learning loss calculated based on video features of an augmented video of the sample video and a preset negative sample video. The second loss is a similarity ranking loss calculated based on video features of the sample video and captured videos of multiple sizes. The captured videos of multiple sizes are videos obtained by capturing the sample video in multiple sizes in the video frame dimension.
[0357] A calculation unit 1230, configured to calculate a similarity between a query video feature and each candidate video feature;
[0358] The recommendation unit 1240 is used to recommend videos based on similarity.
[0359] Optionally, in one implementation, the training process of the first neural network model includes the following steps:
[0360] Acquire multiple first sample videos and multiple preset negative sample videos, and perform video amplification on each first sample video to obtain multiple amplified videos, where the amplified videos include the first sample video and a video obtained by amplifying the first sample video;
[0361] Extracting video features from the amplified video based on the first neural network model to obtain amplified video features, and extracting video features from multiple preset negative sample videos based on the second neural network model to obtain multiple negative sample video features;
[0362] Calculate the contrastive learning loss based on the amplified video features and the negative sample video features to obtain the first loss;
[0363] Cut each first sample video into multiple sizes on a video frame dimension to obtain multiple cut videos, and extract video features from the first sample video and the multiple cut videos based on a first neural network model to obtain first sample video features and multiple cut video features;
[0364] Calculate the similarity ranking loss based on the first sample video feature, the multiple intercepted video features, and the similarity ranking relationship between the multiple intercepted videos and the first sample video to obtain a second loss;
[0365] The parameters of the first neural network model are updated according to the first loss and the second loss.
[0366] Optionally, in one implementation, the training process of the first neural network model further includes:
[0367] Obtaining multiple second sample videos and a classification label corresponding to each second sample video;
[0368] Extracting video features from the second sample video based on the first neural network model to obtain second sample video features;
[0369] Classify the second sample video features based on a preset classification network layer to obtain a classification prediction probability value;
[0370] The classification loss is calculated based on the classification prediction probability value and the classification label to obtain the third loss;
[0371] The parameters of the first neural network model are updated according to the first loss and the second loss, including:
[0372] The parameters of the first neural network model are updated according to the first loss, the second loss and the third loss.
[0373] Optionally, in one implementation, each first sample video is amplified to obtain a plurality of amplified videos, including:
[0374] Performing time-series amplification on the first sample video to obtain a first sub-amplified video;
[0375] Performing spatial amplification on the first sample video to obtain a second sub-amplified video;
[0376] Performing spatial amplification on the first sub-amplified video to obtain a third sub-amplified video;
[0377] A plurality of augmented videos are determined according to the first sub-amplified video, the second sub-amplified video, the third sub-amplified video, and the first sample video.
[0378] Optionally, in one implementation, before performing time series amplification on the first sample video to obtain the first sub-amplified video, the training process of the first neural network model further includes:
[0379] Splitting the first sample video into a plurality of video segments, and extracting a video frame from each video segment to obtain a plurality of video frames;
[0380] Performing time-series amplification on the first sample video to obtain a first sub-amplified video includes:
[0381] Performing time-sequential amplification on multiple video frames to obtain multiple first sub-amplified video frames;
[0382] The video features of the augmented video are extracted based on the first neural network model to obtain the augmented video features, including:
[0383] Video features are extracted from multiple-frame amplified video frames based on the first neural network model to obtain amplified video features. The multiple-frame amplified video frames include multiple-frame video frames, multiple-frame first sub-amplified video frames obtained only based on time amplification, multiple-frame second sub-amplified video frames obtained only based on spatial amplification, and multiple-frame third sub-amplified video frames obtained based on both time amplification and spatial amplification.
[0384] Optionally, in one implementation, the first neural network model includes a first network layer and a second network layer, and video feature extraction is performed on multiple augmented video frames based on the first neural network model to obtain augmented video features, including:
[0385] Based on the first network layer, image features are extracted from the multiple augmented video frames to obtain multiple frame features;
[0386] Based on the second network layer, multiple frame features are fused to obtain augmented video features.
[0387] Optionally, in one implementation, feature fusion is performed on multiple frame features based on the second network layer to obtain augmented video features, including:
[0388] Based on performing linear transformation on the features of the plurality of frames, a first intermediate matrix, a second intermediate matrix and a third intermediate matrix are obtained;
[0389] Normalizing the first intermediate matrix and the transposed matrix of the second intermediate matrix, and multiplying the normalized matrix by the third intermediate matrix to obtain a plurality of frame fusion results;
[0390] Calculate the average value of multiple frame fusion results to obtain the amplified video features.
[0391] Optionally, in one implementation, the feature extraction unit 1220 is specifically configured to:
[0392] Extracting multiple query video frames from the query video, and extracting multiple candidate video frames from each candidate video;
[0393] Extracting image features from multiple query video frames based on the first network layer to obtain multiple query frame features, and extracting image features from multiple candidate video frames based on the first network layer to obtain multiple candidate frame features;
[0394] Based on the second network layer, feature fusion is performed on multiple query frame features to obtain query video features, and based on the second network layer, feature fusion is performed on multiple candidate frame features corresponding to each candidate video to obtain multiple candidate video features.
[0395] Optionally, in one implementation, the feature extraction unit 1220 is specifically configured to:
[0396] Splitting the query video into a plurality of query video segments, and splitting each candidate video into a plurality of candidate video segments;
[0397] Extracting a query video frame from each query video segment to obtain multiple query video frames;
[0398] A candidate video frame is extracted from each candidate video segment to obtain multiple candidate video frames corresponding to each candidate video.
[0399] Optionally, in one implementation, the training process of the first neural network model further includes:
[0400] Get the momentum update coefficients of the model parameters;
[0401] The parameters of the second neural network model are updated based on the updated parameters of the first neural network model and the momentum update coefficient.
[0402] Optionally, in one implementation, the recommendation unit 1240 is specifically configured to:
[0403] Determine a video among multiple candidate videos whose similarity to the query video is less than a preset threshold as a first target video;
[0404] Sorting the plurality of first target videos in descending order according to the similarity with the query video, and determining a preset number of videos ranked first as second target videos;
[0405] Recommending multiple second target videos to the recommendation object.
[0406] Reference Fig.13 , Fig.13 The structural block diagram of the terminal 140 for implementing the video recommendation method of the embodiment of the present disclosure includes: a radio frequency (RF) circuit 1310, a memory 1315, an input unit 1330, a display unit 1340, a sensor 1350, an audio circuit 1360, a wireless fidelity (WiFi) module 1370, a processor 1380, and a power supply 1390. Those skilled in the art can understand that Fig.13 The structure of the terminal 140 shown does not constitute a limitation on a mobile phone or a computer, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0407] The RF circuit 1310 may be used for receiving and sending signals during information transmission or communication. In particular, after receiving downlink information from the base station, the information is sent to the processor 1380 for processing. In addition, the uplink data is sent to the base station.
[0408] The memory 1315 may be used to store software programs and modules. The processor 1380 executes various functional applications and data processing of the content terminal by running the software programs and modules stored in the memory 1315 .
[0409] The input unit 1330 may be used to receive input digital or character information and generate key signal input related to the setting and function control of the content terminal. Specifically, the input unit 1330 may include a touch panel 1331 and other input devices 1332 .
[0410] The display unit 1340 may be used to display input information or provided information and various menus of the content terminal. The display unit 1340 may include a display panel 1341.
[0411] The audio circuit 1360 , the speaker 1361 , and the microphone 1362 may provide an audio interface.
[0412] In this embodiment, the processor 1380 included in the target terminal 140 can execute the video recommendation method of the previous embodiment.
[0413] The object terminal 140 of the embodiment of the present disclosure includes but is not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle terminals, aircraft, etc. The embodiment of the present invention can be applied to various scenarios, including but not limited to human-computer interaction, knowledge recall, etc.
[0414] Fig.14 A block diagram of the structure of a portion of the server 110 for implementing the video recommendation method of the embodiment of the present disclosure. The server 110 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPUs) 1422 (for example, one or more processors) and a memory 1432, and one or more storage media 1430 (for example, one or more mass storage devices) storing application programs 1442 or data 1444. Among them, the memory 1432 and the storage medium 1430 can be short-term storage or permanent storage. The program stored in the storage medium 1430 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 1422 can be configured to communicate with the storage medium 1430 and execute a series of instruction operations in the storage medium 1430 on the server.
[0415] The server 110 may also include one or more power supplies 1426, one or more wired or wireless network interfaces 1450, one or more input and output interfaces 1458, and / or one or more operating systems 1441, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0416] The central processor 1422 in the server 110 may be configured to execute the video recommendation method according to the embodiment of the present disclosure.
[0417] The embodiments of the present disclosure further provide a computer-readable storage medium, which is used to store program codes, and the program codes are used to execute the video recommendation methods of the aforementioned embodiments.
[0418] The embodiment of the present disclosure also provides a computer program product, which includes a computer program. A processor of a computer device reads and executes the computer program, so that the computer device executes and implements the above-mentioned video recommendation method.
[0419] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present disclosure and the above-mentioned drawings are used to distinguish similar contents, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present disclosure described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "comprises" and "comprising" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0420] It should be understood that in the present disclosure, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated content, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the associated content before and after is in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0421] It should be understood that in the description of the embodiments of the present disclosure, the meaning of multiple (or multiple items) is more than two, greater than, less than, exceed, etc. are understood as not including the number, and above, below, within, etc. are understood as including the number.
[0422] In the embodiments of the present disclosure, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0423] In the several embodiments provided in the present disclosure, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0424] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0425] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0426] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store program codes.
[0427] It should also be understood that the various implementations provided in the embodiments of the present disclosure can be combined arbitrarily to achieve different technical effects.
[0428] The above is a specific description of the implementation methods of the present disclosure, but the present disclosure is not limited to the above implementation methods. Technical personnel familiar with the art can also make various equivalent modifications or substitutions without violating the spirit of the present disclosure. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present disclosure.
Claims
1. A video recommendation method, characterized in that: include: Acquire a query video and a candidate video library, wherein the candidate video library includes multiple candidate videos; Based on the first neural network model, video features are extracted from the query video and the multiple candidate videos to obtain query video features and multiple candidate video features. The first neural network model is obtained based on target loss training. The target loss includes a first loss and a second loss. The first loss is a comparative learning loss calculated based on video features of an augmented video of a first sample video and a preset negative sample video. The calculation process of the second loss includes: combining the first sample video feature of the first sample video with multiple intercepted video features of multiple sizes of intercepted videos in pairs to obtain multiple feature comparison groups. The multiple sizes of intercepted videos are multiple sizes of interceptions of the first sample video in the video frame dimension. The obtained video; calculating the third training similarity between the two video features in each of the feature comparison groups; generating a similarity matrix according to the plurality of the third training similarities, wherein the row dimension and the column dimension of the similarity matrix are arranged based on the video size sorting of the first sample video and the captured videos of the plurality of sizes; for each column in the similarity matrix, determining the matrix value whose corresponding row number is greater than or equal to the corresponding column number as the target matrix value, and determining the matrix value whose corresponding row number is greater than the corresponding row number of the target matrix value as the comparison matrix value of the target matrix value; calculating the difference between the comparison matrix value and the corresponding target matrix value to obtain the sorting difference; calculating the similarity sorting loss based on the sorting difference to obtain the second loss; Calculating the similarity between the query video feature and each of the candidate video features; Video recommendations are made based on the similarity.
2. The method according to claim 1, characterized in that The training process of the first neural network model includes the following steps: Acquire multiple first sample videos and multiple preset negative sample videos, and perform video amplification on each of the first sample videos to obtain multiple amplified videos, wherein the amplified videos include the first sample videos and videos obtained by performing video amplification on the first sample videos; Performing video feature extraction on the amplified video based on the first neural network model to obtain an amplified video feature, and performing video feature extraction on the multiple preset negative sample videos based on the second neural network model to obtain multiple negative sample video features; Calculate the contrastive learning loss based on the amplified video feature and the negative sample video feature to obtain a first loss; Cut each of the first sample videos into multiple sizes on a video frame dimension to obtain multiple cut videos, and extract video features from the first sample video and the multiple cut videos based on the first neural network model to obtain first sample video features and multiple cut video features; Calculating a similarity ranking loss based on the first sample video feature, the multiple intercepted video features, and a similarity ranking relationship between the multiple intercepted videos and the first sample video to obtain a second loss; The parameters of the first neural network model are updated according to the first loss and the second loss.
3. The method according to claim 2, characterized in that The method further comprises: Obtaining a plurality of second sample videos and a classification label corresponding to each of the second sample videos; Extracting video features from the second sample video based on the first neural network model to obtain second sample video features; Classifying the second sample video feature based on a preset classification network layer to obtain a classification prediction probability value; Calculate the classification loss based on the classification prediction probability value and the classification label to obtain a third loss; The updating of the parameters of the first neural network model according to the first loss and the second loss includes: The parameters of the first neural network model are updated according to the first loss, the second loss and the third loss.
4. The method according to claim 2, characterized in that: The step of performing video amplification on each of the first sample videos to obtain a plurality of amplified videos includes: Performing time-series amplification on the first sample video to obtain a first sub-amplified video; Performing spatial amplification on the first sample video to obtain a second sub-amplified video; spatially amplifying the first sub-amplified video to obtain a third sub-amplified video; A plurality of augmented videos are determined according to the first sub-amplified video, the second sub-amplified video, the third sub-amplified video, and the first sample video.
5. The method according to claim 4, characterized in that Before performing time-series amplification on the first sample video to obtain a first sub-amplified video, the method further includes: Splitting the first sample video into a plurality of video segments, and extracting a video frame from each of the video segments to obtain a plurality of video frames; The step of performing time-series amplification on the first sample video to obtain a first sub-amplified video includes: Performing time-sequential amplification on the multiple video frames to obtain multiple first sub-amplified video frames; The extracting video features from the amplified video based on the first neural network model to obtain amplified video features includes: Video features are extracted from multiple-frame amplified video frames based on a first neural network model to obtain amplified video features. The multiple-frame amplified video frames include the multiple-frame video frames, the multiple-frame first sub-amplified video frames obtained only based on time amplification, the multiple-frame second sub-amplified video frames obtained only based on spatial amplification, and the multiple-frame third sub-amplified video frames obtained based on both time amplification and spatial amplification.
6. The method according to claim 5, characterized in that The first neural network model includes a first network layer and a second network layer, and the video feature extraction of multiple augmented video frames based on the first neural network model to obtain augmented video features includes: Based on the first network layer, image feature extraction is performed on the multiple augmented video frames to obtain multiple frame features; The plurality of frame features are subjected to feature fusion based on the second network layer to obtain an augmented video feature.
7. The method according to claim 6, characterized in that The step of fusing the plurality of frame features based on the second network layer to obtain an amplified video feature includes: Based on performing a linear transformation on the plurality of frame features, a first intermediate matrix, a second intermediate matrix and a third intermediate matrix are obtained; performing normalization processing on the transposed multiplication of the first intermediate matrix and the second intermediate matrix, and multiplying the normalization processing result by the third intermediate matrix to obtain multiple frame fusion results; An average value of the fusion results of the multiple frames is calculated to obtain the augmented video feature.
8. The method according to claim 6, characterized in that The extracting video features of the query video and the multiple candidate videos based on the first neural network model to obtain query video features and multiple candidate video features includes: Extracting a plurality of query video frames from the query video, and extracting a plurality of candidate video frames from each of the candidate videos; Extracting image features from the multiple query video frames based on the first network layer to obtain multiple query frame features, and extracting image features from the multiple candidate video frames based on the first network layer to obtain multiple candidate frame features; Based on the second network layer, feature fusion is performed on the multiple query frame features to obtain query video features, and based on the second network layer, feature fusion is performed on the multiple candidate frame features corresponding to each candidate video to obtain multiple candidate video features.
9. The method according to claim 8, characterized in that The step of extracting a plurality of query video frames from the query video and extracting a plurality of candidate video frames from each of the candidate videos comprises: Splitting the query video into a plurality of query video segments, and splitting each of the candidate videos into a plurality of candidate video segments; Extracting a query video frame from each query video segment to obtain multiple query video frames; A candidate video frame is extracted from each of the candidate video segments to obtain multiple candidate video frames corresponding to each of the candidate videos.
10. The method according to claim 2, characterized in that After updating the parameters of the first neural network model according to the first loss and the second loss, the method further includes: Get the momentum update coefficients of the model parameters; The parameters of the second neural network model are updated based on the updated parameters of the first neural network model and the momentum update coefficient.
11. The method according to claim 1, characterized in that: The recommending videos according to the similarity includes: Determine a video among the multiple candidate videos whose similarity to the query video is less than a preset threshold as a first target video; Sorting the plurality of first target videos in descending order according to the similarity with the query video, and determining a preset number of videos ranked first as second target videos; Recommending a plurality of the second target videos to the recommendation object.
12. A video recommendation device, characterized in that: include: An acquisition unit, configured to acquire a query video and a candidate video library, wherein the candidate video library includes a plurality of candidate videos; The feature extraction unit is used to extract video features from the query video and the multiple candidate videos based on a first neural network model to obtain query video features and multiple candidate video features, wherein the first neural network model is obtained based on target loss training, and the target loss includes a first loss and a second loss, wherein the first loss is a comparative learning loss calculated based on video features of an augmented video of a first sample video and a preset negative sample video, and the calculation process of the second loss includes: combining the first sample video feature of the first sample video with multiple intercepted video features of multiple sizes of intercepted videos in pairs to obtain multiple feature comparison groups, wherein the multiple sizes of intercepted videos are multiple sizes of the first sample video in a video frame dimension. sized captured videos; calculating a third training similarity between two video features in each of the feature comparison groups; generating a similarity matrix based on a plurality of the third training similarities, wherein the row dimension and the column dimension of the similarity matrix are arranged based on the video size sorting of the first sample video and the captured videos of the plurality of sizes; for each column in the similarity matrix, determining a matrix value whose corresponding row number is greater than or equal to the corresponding column number as a target matrix value, and determining a matrix value whose corresponding row number is greater than the corresponding row number of the target matrix value as a comparison matrix value of the target matrix value; calculating the difference between the comparison matrix value and the corresponding target matrix value to obtain a sorting difference; calculating a similarity sorting loss based on the sorting difference to obtain a second loss; A calculation unit, used for calculating the similarity between the query video feature and each of the candidate video features; The recommendation unit is used to recommend videos according to the similarity.
13. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the video recommendation method according to any one of claims 1 to 11 is implemented.
14. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the video recommendation method according to any one of claims 1 to 11 is implemented.
15. A computer program product, comprising a computer program, wherein the computer program is read and executed by a processor of a computer device, so that the computer device executes the video recommendation method according to any one of claims 1 to 11.
