A cross-modal music generation method and device for film and television soundtracks

A cross-modal music generation model is built through the frozen ViT model and cross-attention mechanism, which solves the problem of low efficiency of traditional video soundtracks, achieves high-quality, personalized video music generation, and improves creation efficiency and the integration of music and video. Spend.

CN118551074BActive Publication Date: 2024-10-25ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411025431.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-10-25
Estimated Expiration
2044-07-30

AI Technical Summary

Technical Problem

Traditional video soundtrack creation is inefficient and difficult to ensure the perfect integration of music and video content. Moreover, existing soundtrack tools lack personalized options, limiting the creative space and work quality.

Method used

The frozen ViT model, spatial feature adapter and timing controller are used to build a cross-modal music generation model, which is cross-trained through visual features and music tags to generate music that is consistent with the video content.

Benefits of technology

Significantly improves the efficiency and music quality of video soundtracks, reduces memory usage and training time, and enables a more personalized and efficient video production process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118551074B_ABST
    Figure CN118551074B_ABST
Patent Text Reader

Abstract

The present invention discloses a cross-modal music generation method and device for film and television soundtracks. The generation method only and simultaneously trains a spatial feature adapter and a timing controller. Compared with the prior art, the present invention can only load the spatial feature adapter and the timing controller that need to be trained into a GPU, and does not need to train the spatial feature adapter and the timing controller separately, thereby significantly reducing the use of memory and improving the training speed. Music features related to music are screened out from a visual feature vector through the trained spatial feature adapter and the final music query vector, and the predicted music embedding that is relatively consistent with the content of the video can be predicted by the trained timing controller, thereby obtaining predicted music that is relatively consistent with the content of the video and relatively realistic.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of neural networks, and in particular relates to a cross-modal music generation method and device for film and television soundtracks. Background Art

[0002] In the digital multimedia era, video has become an indispensable part of people's daily life, and music, as the core element of video, plays a key role in enhancing the audience's immersion and experience quality. However, traditional video soundtrack creation mainly relies on manual selection and editing, which is not only time-consuming and labor-intensive, but also requires creators to have professional music knowledge and skills. For the growing number of amateur video editing enthusiasts, they usually need to spend a lot of time and energy searching for tracks in the music library that match the emotions of the video content to compose the video soundtrack, and the selected music may also have copyright issues. This manual soundtrack method is inefficient and it is difficult to ensure the perfect integration of music and video content, which limits the creative space and the quality of the work.

[0003] In response to the above problems, although there are some music tools on the market (such as YouTube Audio Library, Epidemic Sound, etc.) that provide pre-made music libraries, allowing users to easily add music to videos, these tools often lack sufficient personalized options. It is difficult for users to find music in these tools that can accurately match the specific emotions, scenes, and rhythms of the video, resulting in a low degree of integration between the music and the video content, affecting the overall viewing experience. In addition, the music libraries of these tools may not meet the unique needs of all users, thus limiting the diversity and innovation of creation. Therefore, it is very important to develop a technology that can automatically generate music based on video content to achieve a more efficient and personalized video production process.

[0004] The invention patent application with the publication number CN113282788A discloses a method for recommending video soundtracks based on neural network technology, including: inputting a video set containing multiple videos to be matched with music and a music library containing multiple soundtracks to be selected into a pre-trained style label prediction model for analysis, obtaining video style label information corresponding to the video set and audio style label information corresponding to each soundtrack to be selected; calculating the matching value of the video set and each soundtrack to be selected according to the video style label information corresponding to the video set and the audio style label information corresponding to each soundtrack to be selected; and selecting the target soundtrack from the music library according to the matching value of the video set and each soundtrack to be selected as the soundtrack of the video set. It can be seen that the present invention can enable the pre-trained style label prediction model to have a better fusion capability for the features of the two different modalities of audio and video, thereby improving the matching quality of the final recommended soundtrack and video.

[0005] The invention patent application with publication number CN111767431A discloses a method and device for video music matching. A specific implementation of the method includes: obtaining a video to be matched with music; inputting the video to be matched with music into a pre-trained video emotion classification model to obtain at least one emotion classification information corresponding to the video to be matched with music and the probability corresponding to the emotion classification information; obtaining a set of music information to be recalled corresponding to the video to be matched with music, wherein each piece of music information in the set of music information to be recalled corresponds to at least one emotion label; based on the matching of at least one emotion classification information corresponding to the video to be matched with music and the probability with the emotion label corresponding to each piece of music information in the set of music information to be recalled, a list of recalled music information is generated. This implementation makes full use of the information of the emotional dimension of the video and the music matching, thereby effectively improving the matching degree of the video music matching.

[0006] Although there are some video soundtrack models in the academic field (such as V-MusProd, M2UGen, etc.), such as the soundtrack model disclosed in the above patent, the disclosed soundtrack model establishes the connection between video and music through a limited set of explicit features, or uses language descriptions for bridging. However, these methods may cause the model to extract redundant information and ignore key features related to music, thereby affecting the audio-visual consistency and the quality of generated music. Summary of the invention

[0007] The present invention provides a cross-modal music generation method for film and television soundtracks, which can efficiently generate high-quality music that is relatively consistent with the video.

[0008] The present invention provides a cross-modal music generation method for film and television soundtracks, comprising:

[0009] Obtain multiple videos and corresponding music tags, convert the music tags into true music marker values, and use the multiple videos as sample sets;

[0010] Constructing a training model, the training model includes a frozen ViT model, a spatial feature adapter and a timing controller, encoding the sample through the ViT model to obtain a visual feature vector, filtering out the music-related features of each frame image through the spatial feature adapter based on the visual feature vector and the trainable music query vector, stacking the music-related features of each frame image to obtain a video frame feature sequence, converting the true value of the music tag into a music embedding through multiple linear layers, right-shifting the music embedding to show the true value of the music tag of the frame image before the current frame, obtaining the predicted music embedding of the current frame image through the timing controller based on the right-shifted music embedding and the video frame feature sequence, repeatedly predicting until the predicted music embedding of the last frame image is obtained, stopping the iteration, so as to obtain the predicted music embedding of the current sample;

[0011] A cross-loss function is constructed based on music tags and predicted music embeddings. The spatial feature adapter and the timing controller are trained using the cross-loss function through the sample set to obtain a cross-modal music generation model and the final music query vector.

[0012] When applied, the input video and the final music query vector are input into the cross-modal music generation model to obtain the predicted music embedding of the input video, the predicted music embedding is converted into a music tag prediction value, and the music tag prediction value is decoded to obtain the predicted music.

[0013] Preferably, obtaining music-related features of each frame of image through a spatial feature adapter based on the visual feature vector and the initial music query vector includes:

[0014] The spatial feature adapter includes multiple layers of spatial cross-attention layers. In each layer of spatial cross-attention layers, a trainable music query vector is used as a query for the spatial cross-attention layer, and a visual feature vector is used as a key and value for the spatial cross-attention layer. The trainable music query vector is updated during the training process, and initial music-related features are extracted from the visual feature vector based on the updated trainable music query vector. The initial music-related features output by each layer of spatial cross-attention layer are averaged to obtain the music-related features of each frame image.

[0015] Preferably, extracting initial music-related features from the visual feature vector based on the updated trainable music query vector includes:

[0016] The trainable music query vector used as the query is dot-producted with the visual feature vector, scaled and normalized to form the music feature weight, and the music feature weight is dot-producted with the visual feature vector to obtain the initial music-related features.

[0017] Preferably, obtaining the predicted music embedding of the current frame image based on the right-shifted music embedding and the video frame feature sequence through a timing controller includes:

[0018] The timing controller includes a temporal cross-attention layer, which uses the right-shifted music embedding as a query of the temporal cross-attention layer, uses the video frame feature sequence as the key and value of the temporal cross-attention layer, performs dot product, scaling and normalization on the right-shifted music embedding and the video frame feature sequence to obtain the music embedding weight, and performs dot product again on the music embedding weight and the video frame feature sequence to obtain the predicted music embedding of the current frame image.

[0019] Preferably, the sample is encoded by the ViT model to obtain a visual feature vector, including:

[0020] Each frame image in the sample is split into multiple image blocks, each image block is converted into a vector representation, and the category code and the corresponding position code are added to obtain an embedded vector. The encoder of the Transformer of the ViT model is used to encode the embedded vector to obtain a visual feature vector.

[0021] Preferably, the embedding vector is encoded using a Transformer encoder to obtain a visual feature vector, including:

[0022] The encoder of the Transformer includes a multi-layer block network of multi-head self-attention and feedforward networks, and the embedded vector is sequentially passed through the multi-layer block network of multi-head self-attention and feedforward networks to obtain a hidden visual feature vector.

[0023] Preferably, converting the music tag into the music mark true value includes: compressing the music tag into a discrete music mark true value through a MusicGen encoder and residual vector quantization in sequence.

[0024] Preferably, inputting the input video and the final music query vector into the cross-modal music generation model to obtain the predicted music embedding of the input video includes:

[0025] The input video is input into the ViT model to obtain a visual feature vector. The visual feature vector and the final music query vector are input into the trained spatial feature adapter to obtain a video frame feature sequence. The video frame feature sequence and the music embedding corresponding to the frame image before the current frame are input into the trained timing controller to obtain the predicted music embedding of the current frame image. The prediction is repeated until the predicted music embedding of the last frame image is completed to obtain the predicted music embedding of the input video.

[0026] On the other hand, a cross-modal music generation device for film and television soundtracks includes a memory and one or more processors, wherein the memory stores executable code, and when the one or more processors execute the executable code, they are used to implement the cross-modal music generation method for film and television soundtracks.

[0027] Compared with the prior art, the present invention has the following beneficial effects:

[0028] The present invention only trains the spatial feature adapter and the timing controller at the same time. Compared with the prior art, the present invention can only load the spatial feature adapter and the timing controller that need to be trained into the GPU, and there is no need to train the spatial feature adapter and the timing controller separately, thereby significantly reducing the use of memory and improving the training speed.

[0029] The trained spatial feature adapter and the final music query vector are used to filter out music features related to music from the visual feature vector, and the trained timing controller is able to predict a predicted music embedding that is relatively consistent with the content of the video, thereby obtaining predicted music that is relatively consistent with the video content and relatively realistic. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 A flowchart of a cross-modal music generation method for film and television soundtracks provided in a specific embodiment of the present invention;

[0031] Figure 2 A flowchart of a cross-modal music generation method for film and television soundtracks provided in a specific embodiment of the present invention;

[0032] Figure 3 A flowchart of spatial self-attention in the ViT model provided by a specific embodiment of the present invention;

[0033] Figure 4 A flow chart of spatial cross-attention in a spatial feature adapter provided for a specific embodiment of the present invention;

[0034] Figure 5 A timing cross-attention flow chart in a timing controller provided for a specific embodiment of the present invention. DETAILED DESCRIPTION

[0035] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0036] A specific embodiment of the present invention extracts semantic features of video frames through a frozen ViT model to obtain a visual feature vector, extracts music-related features of the visual feature vector through a trained spatial feature adapter and music query vector, and iterates based on music-related features through a trained timing controller to obtain a predicted music embedding consistent with the video content. Since only the spatial feature adapter and the timing controller are trained, the creation cost of the video soundtrack process is effectively reduced and the creation efficiency is improved.

[0037] The specific embodiment of the present invention provides a cross-modal music generation method for film and television soundtracks, such as Figure 1 and Figure 2 As shown, including:

[0038] (1) Obtain multiple videos and corresponding music labels, convert the music labels into true music tag values, and use the obtained multiple videos as sample sets.

[0039] (2) Constructing a training model. The training model provided by the specific embodiment of the present invention includes a frozen ViT (Vision Transformer) model, a spatial feature adapter and a timing controller: The specific embodiment of the present invention uses the ViT model to find the connection between each image block in each frame image to obtain a visual feature vector, and uses the spatial cross-attention mechanism of the spatial feature adapter to filter out music-related features from the visual feature vector, and obtains a music query vector for screening during the training process, and uses the temporal cross-attention mechanism of the timing controller to predict the music embedding based on the video frame feature sequence and the right-shifted music embedding to obtain the predicted music embedding of the current sample.

[0040] The ViT model adopted in the specific embodiment of the present invention splits each frame image in the sample into multiple image blocks, converts each image block into a vector representation, and adds category coding and corresponding position coding to obtain an embedded vector. The encoder of the Transformer of the ViT model is used to encode the embedded vector to obtain a visual feature vector.

[0041] The Transformer encoder provided by a specific embodiment of the present invention includes a multi-layer block network of multi-head self-attention and feedforward networks, and the embedded vector is sequentially passed through the multi-layer block network of multi-head self-attention and feedforward networks to obtain a hidden visual feature vector.

[0042] In a specific embodiment, the specific embodiment of the present invention uses a pre-trained ViT-L / 14@336px model as a visual encoder. The ViT-L / 14@336px model is also the best feature extraction model in CLIP (Contrastive Language-Image Pre-Training). The core process is to divide the image into a series of fixed-size pixel blocks, and convert the divided pixel blocks into vector representations. At the same time, the category code and position code are added to the vector representation to obtain an embedded vector. The category code and position code are used to capture the overall information of the image and the position information of the pixel block respectively. The embedded vector is encoded using the Transformer encoder, that is, the embedded vector is processed by a 12-layer block network including multi-head self-attention and feedforward networks to obtain the hidden features of the vision, that is, the visual feature vector.

[0043] The representation dimension of the visual feature vector output by the specific embodiment of the present invention is (577, 1024), where 577 represents the number of 24×24 image blocks plus a special mark in the 336×336 input image, and 1024 corresponds to the hidden dimension size of the Transformer. In view of its excellent performance in visual feature extraction, the parameters of this module are fixed during the training process and do not participate in the training. The visual feature vector extracted by this module will also be applied to subsequent modules as video conditional prompts.

[0044] The attention mechanism provided by the specific embodiment of the present invention is a core component of the Transformer architecture. It can be regarded as a function that maps a query and a set of key-value pairs to the output. Specifically, the weights are obtained by calculating the compatibility function (usually the dot product) between the query and the corresponding key. Then, these weights are normalized and assigned to each value. The specific embodiment of the present invention sets , and Represents query, key and value, Representing the dimension, the attention mechanism can be written as:

[0045]

[0046] Intuitively, the attention mechanism weighs the relevance of values ​​by key and query. The higher the weight value, the stronger the relevance between the corresponding value and the query.

[0047] In the Transformer of the ViT model provided in the specific embodiment of the present invention, spatial self-attention is a basic mechanism for extracting spatial visual features of the block image to obtain a visual feature vector. The ViT model divides each frame image in the video into a series of continuous pixel blocks, and it becomes crucial to determine the association between the pixel blocks, such as Figure 3 As shown in the figure, in spatial self-attention, the embedded vector is respectively subjected to three different linear transformation matrices to obtain Q, K and V of spatial self-attention. Then, Q and K are dot-producted, scaled and normalized to obtain weights, and the weights are dot-producted with V again to find the connection between the pixel blocks of the image frame, thereby obtaining the visual feature vector.

[0048] Since the ViT model provided in the specific embodiment of the present invention is a model with frozen parameters, it can be pre-trained outside the GPU of the specific embodiment of the present invention. The specific embodiment of the present invention only uses the pre-trained ViT model, thereby saving training resources, and the ViT model is pre-trained by aligning with the text, so self-attention is closely related to semantic feature extraction. This mechanism not only helps the ViT model to better understand the image content, but also lays the foundation for the subsequent generation module.

[0049] The purpose of the spatial feature adapter provided in a specific embodiment of the present invention is to convert a visual feature vector representing a semantic feature into a music-related feature. The spatial feature adapter includes multiple layers of spatial cross-attention layers. First, a trainable query, that is, a trainable music query vector, is constructed. In each layer of the spatial cross-attention layer, the trainable music query vector is used as the query of the spatial cross-attention layer, and the visual feature vector is used as the key and value of the spatial cross-attention layer. The trainable music query vector is updated during the training process. The visual feature vector is extracted and converted based on the updated trainable music query vector to obtain initial music-related features. The initial music-related features output by each layer of the spatial cross-attention layer are averaged to obtain the music-related features of each frame of the image.

[0050] In a specific embodiment, the present invention uses a trainable QFormer module as a spatial feature adapter. First, a dimension R is created. 16×D The initial music query vector (D represents the hidden dimension) is continuously changed during the training process and becomes relevant to music. The music-related visual features, i.e., music-related features, are extracted through the cross-attention between the music-related query and the visual feature vector. In QFormer, the specific embodiment of the present invention applies the self-attention layer and the cross-attention layer between the queries and the corresponding feedforward network blocks. Since the queries are trained together with the model, the specific embodiment of the present invention considers that these queries are highly relevant to music, thereby correctly guiding the screening and filtering of visual features.

[0051] The specific embodiment of the present invention provides a method for extracting initial music-related features from a visual feature vector based on an updated trainable music query vector, such as Figure 4 As shown, including:

[0052] The trainable music query vector used as the query is dot-producted with the visual feature vector, scaled and normalized to form the music feature weight, and the music feature weight is dot-producted with the visual feature vector to obtain the initial music-related features.

[0053] In one specific embodiment, in spatial cross attention, in order to extract visual feature vectors that are closely related to music rather than text from each image, the present invention modifies the attention mechanism by changing the query. Figure 4 As shown, the present invention defines 16 trainable queries as Q, and retains the output image block feature visual feature vector of the visual feature extraction module as K and V to calculate the cross attention, and finally obtains the feature encoding output. Therefore, the spatial cross attention mechanism uses these music-related queries to extract the most music-related features from each image.

[0054] The timing controller provided by the specific embodiment of the present invention utilizes the cross attention between the music embedding and the video frame feature sequence to enhance the correlation between the generated music and the video, inputs the video frame feature sequence into the linear layer to change the feature dimension to obtain its high-dimensional features, and inputs the high-dimensional features of the video frame sequence and the right-shifted music embedding into the timing cross attention layer to obtain the predicted music embedding of the sample. In one embodiment, the timing controller is a MusicGen controller, and the MusicGen provided in this embodiment also designs various interleaving modes of different codebooks to improve the quality of generated music. In general, the MusicGen model has a large number of parameters and has been trained with a wide range of data sets, showing excellent generation capabilities and quality in text-music generation tasks, so the present invention applies it to the music generation module.

[0055] like Figure 5 As shown, the timing controller includes a temporal cross-attention layer, which uses the right-shifted music embedding as the query of the temporal cross-attention layer, uses the video frame feature sequence as the key and value of the temporal cross-attention layer, performs dot product, scaling and normalization on the right-shifted music embedding and the video frame feature sequence to obtain the music embedding weight, and performs dot product again on the music embedding weight and the video frame feature sequence to obtain the predicted music embedding of the current frame image.

[0056] After extracting spatial visual features, the video frame feature sequence is used as a conditional cue to guide the music generation process. However, the video content contains not only the spatial information of each frame, but also the temporal information between frames. Therefore, Figure 5 As shown, in order to make full use of this time information, the right-shifted F m Converted to Q, the present invention sets the music embedding as Q, and the video frame feature sequence as K and V, and finally obtains the predicted output of the next frame image music encoding, that is, the predicted music embedding. In addition, Figure 1 As shown in Figure 1, the prediction of music tags in the controller is continuous. Each tag is affected by the previous tag and will cyclically affect the subsequent music tags. Through this repeated prediction method, the model can combine spatial and temporal information to generate music that is highly relevant to the video content. The repeated prediction method converts the music tag M (discrete) into F m , vector F m Shift right to show the true value of the frame before the current prediction frame, and change F m The right shift is converted to vector Q. Based on vector Q, the value of the current frame is predicted through temporal cross attention. After the prediction value of each frame is completed (probability value, vector), the predicted music embedding F' is obtained. m , the predicted music embedding includes the probability of each type of tag, and the predicted music embedding is then cross-lossed with the corresponding music tag M.

[0057] The specific process of converting a music tag into a true value of a music mark provided by a specific embodiment of the present invention includes:

[0058] The music tags are compressed into discrete (RVQ, Residual Vector Quantization) music tags through the MusicGen encoder and residual vector quantization in turn, and the vector after music encoding is searched in the codebook to obtain the final music tag.

[0059] (3) Based on music tags M and predicted music embedding F' m A cross-loss function is constructed, and the spatial feature adapter and timing controller are trained using the cross-loss function through the sample set to obtain the cross-modal music generation model and the final music query vector.

[0060] (4) When applied, the input video and the final music query vector are input into the cross-modal music generation model to obtain the predicted music embedding of the input video, the predicted music embedding is converted into a music tag prediction value, and the music tag prediction value is decoded to obtain the predicted music.

[0061] In a specific embodiment, the input video is input into the frozen ViT model to obtain a visual feature vector, the visual feature vector and the trained query, i.e., the final music query vector, are input into the trained spatial feature adapter to obtain a video frame feature sequence, and the video frame feature sequence and the initial music embedding or the music embedding corresponding to the 0-i frame image before the current frame i+1 are embedded in the spatial feature adapter. Input the trained timing controller to get the predicted music embedding of the current frame i+1 image , by repeating the prediction t×s' times, we get the predicted music embedding F' m , where t is the music duration and s' is the audio music frame rate.

[0062] In a specific embodiment, the training process of the training model is:

[0063] In the frozen ViT model, each video sample Considered as the i-th frame A sequence of which , , , and Represent the duration, video frame rate, image width, height, and number of channels. Each image will be divided into multiple image blocks and represented as frame-level embedding vectors ,in, , , D refers to the feature dimension of the embedding vector, and s represents the image block size, which is set to 14 in ViT-L / 14. The self-attention in the image is obtained by dividing xi Let query, key and value be calculated. After calculating the visual self-attention, the hidden feature can represent the image p of the i-th frame as , where the added value 1 represents a special class marker ( ).

[0064] Since the pre-trained ViT model only focuses on semantic features aligned with text, the present invention designs a trainable QFormer to learn the most relevant features for music through queries. Then, the present invention defines the query , these queries are considered to be music-related after training. Both self-attention and cross-attention are used for trainable query parameters. and denote the number of queries (16) and the number of hidden dimensions, respectively, while the key and value of the cross attention are .

[0065] After multiple cross-attention layers, the attention related to the music of the i-th frame image is obtained. The specific embodiment of the present invention uses the average attention of each query to represent the visual features of the i-th frame image:

[0066]

[0067] Then the hidden features of each image can be expressed as , i is the index of the frame, j is the index of the query number, which is used to represent the global semantic information of the image. Therefore, the video feature can be expressed as , which is composed of Stacked, of which .

[0068] Video features provided by the specific embodiment of the present invention is input to the MusicGen controller for subsequent computational processing. After linear mapping, the music embedding is set as the query, and the video feature During the training process, the audio music first passes through the MusicGen encoder and residual vector quantization to obtain the original music markup. , and then the original music tags are converted into music embeddings through K linear layers ,in, represents the sampling rate of the music notation, Indicates the number of codebooks, and H indicates the size of the hidden feature dimension. During the inference process, the music embedding vector is initialized to a special mark (such as -1, which will not be the same as other values ​​during training or use, and will not be confused), and will be gradually iterated to obtain the predicted music features. The predicted music features can be written as , and will be quantized into music markers in the codebook Finally, through the decoder of MusicGen, the music can be generated in audio format.

[0069] Training CLIP and MusicGen models separately requires expensive computational and time costs, and may even require additional image-text and text-music datasets. To address these issues, the present invention fixes the parameters of the pre-trained visual encoder, music encoder, and music decoder, while focusing on fine-tuning the MusicGen controller to enhance the consistency of music and video. In addition, the model can also inherit the feature extraction capabilities of the ViT model and the music generation capabilities of the MusicGen model.

[0070] Therefore, the present invention can extract all and music markings This means that during training, the visual encoder, music encoder, and music decoder are not loaded into the GPU, which can significantly reduce memory usage and increase training speed.

[0071] In terms of training loss, the present invention adopts each codebook The average cross entropy loss is used to compare the predicted music features and the original music tags :

[0072]

[0073] Wherein, K is the number of codebooks, N is the total number of music frames, and i is the i-th frame of the music.

[0074] On the other hand, the present invention also provides a cross-modal music generation device for film and television soundtracks, including a memory and one or more processors, wherein the memory stores executable code, and when the one or more processors execute the executable code, they are used to implement the cross-modal music generation method for film and television soundtracks.

Claims

1. A cross-modal music generation method for film and television soundtracks, characterized in that: include: Obtain multiple videos and corresponding music tags, convert the music tags into true music marker values, and use the multiple videos as sample sets; Constructing a training model, the training model includes a frozen ViT model, a spatial feature adapter and a timing controller, encoding the sample through the ViT model to obtain a visual feature vector, filtering out the music-related features of each frame image through the spatial feature adapter based on the visual feature vector and the trainable music query vector, stacking the music-related features of each frame image to obtain a video frame feature sequence, converting the true value of the music tag into a music embedding through multiple linear layers, right-shifting the music embedding to show the true value of the music tag of the frame image before the current frame, obtaining the predicted music embedding of the current frame image through the timing controller based on the right-shifted music embedding and the video frame feature sequence, repeatedly predicting until the predicted music embedding of the last frame image is obtained, stopping the iteration, so as to obtain the predicted music embedding of the current sample; A cross-loss function is constructed based on music tags and predicted music embeddings. The spatial feature adapter and the timing controller are trained using the cross-loss function through the sample set to obtain a cross-modal music generation model and the final music query vector. When applied, the input video and the final music query vector are input into the cross-modal music generation model to obtain the predicted music embedding of the input video, the predicted music embedding is converted into a music tag prediction value, and the music tag prediction value is decoded to obtain the predicted music.

2. The cross-modal music generation method for film and television soundtracks according to claim 1 is characterized in that: Based on the visual feature vector and the initial music query vector, the music-related features of each frame image are obtained through the spatial feature adapter, including: The spatial feature adapter includes multiple layers of spatial cross-attention layers. In each layer of spatial cross-attention layers, a trainable music query vector is used as a query for the spatial cross-attention layer, and a visual feature vector is used as a key and value for the spatial cross-attention layer. The trainable music query vector is updated during the training process, and initial music-related features are extracted from the visual feature vector based on the updated trainable music query vector. The initial music-related features output by each layer of spatial cross-attention layer are averaged to obtain the music-related features of each frame image.

3. The cross-modal music generation method for film and television soundtracks according to claim 2 is characterized in that: Initial music-related features are extracted from the visual feature vector based on the updated trainable music query vector, including: The trainable music query vector used as the query is dot-producted with the visual feature vector, scaled and normalized to form the music feature weight, and the music feature weight is dot-producted with the visual feature vector to obtain the initial music-related features.

4. The cross-modal music generation method for film and television soundtracks according to claim 1 is characterized in that: The predicted music embedding of the current frame image is obtained through the timing controller based on the right-shifted music embedding and the video frame feature sequence, including: The timing controller includes a temporal cross-attention layer, which uses the right-shifted music embedding as a query of the temporal cross-attention layer, uses the video frame feature sequence as the key and value of the temporal cross-attention layer, performs dot product, scaling and normalization on the right-shifted music embedding and the video frame feature sequence to obtain the music embedding weight, and performs dot product again on the music embedding weight and the video frame feature sequence to obtain the predicted music embedding of the current frame image.

5. The cross-modal music generation method for film and television soundtracks according to claim 1 is characterized in that: The samples are encoded through the ViT model to obtain visual feature vectors, including: Each frame image in the sample is split into multiple image blocks, each image block is converted into a vector representation, and the category code and the corresponding position code are added to obtain an embedded vector. The encoder of the Transformer of the ViT model is used to encode the embedded vector to obtain a visual feature vector.

6. The cross-modal music generation method for film and television soundtracks according to claim 5 is characterized in that: The Transformer encoder is used to encode the embedding vector to obtain the visual feature vector, including: The encoder of the Transformer includes a multi-layer block network of multi-head self-attention and feedforward networks, and the embedded vector is sequentially passed through the multi-layer block network of multi-head self-attention and feedforward networks to obtain a hidden visual feature vector.

7. The cross-modal music generation method for film and television soundtracks according to claim 1 is characterized in that: The music tags are converted into true values ​​of the music tags, including: the music tags are sequentially compressed into discrete true values ​​of the music tags through a MusicGen encoder and residual vector quantization.

8. The cross-modal music generation method for film and television soundtracks according to claim 1, characterized in that: The input video and the final music query vector are fed into the cross-modal music generation model to obtain the predicted music embedding of the input video, including: The input video is input into the ViT model to obtain a visual feature vector. The visual feature vector and the final music query vector are input into the trained spatial feature adapter to obtain a video frame feature sequence. The video frame feature sequence and the music embedding corresponding to the frame image before the current frame are input into the trained timing controller to obtain the predicted music embedding of the current frame image. The prediction is repeated until the predicted music embedding of the last frame image is completed to obtain the predicted music embedding of the input video.

9. A cross-modal music generation device for film and television soundtracks, characterized in that: It comprises a memory and one or more processors, wherein the memory stores executable codes, and when the one or more processors execute the executable codes, they are used to implement a cross-modal music generation method for film and television soundtracks as described in any one of claims 1-8.