Method for performing genre classification and construction on music based on ResNet18 and Transformer double branches
By using the dual-branch method of ResNet18 and Transformer in music genre classification, combined with the multi-head self-attention mechanism and residual connection, the existing technology solves the music data classification problems of changing music styles and large amounts of data, and achieves a better Accurate and robust music genre classification.
Patent Information
- Application Number
- CN202410702211.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-01
- Publication Date
- 2024-08-23
AI Technical Summary
When existing technologies deal with changing music styles, large amounts of music data, and diverse features, it is difficult to classify music genres accurately and robustly, and cannot fully express the diversity and personality of music.
Using a method based on the dual branch of ResNet18 and Transformer, by building a data enhancement layer, extracting the Mel Spectrogram feature layer, extracting the SincNet feature layer, Transformer Encoder layer and ResNet18 layer, combined with the multi-head self-attention mechanism and residual connection, the audio is captured high-level features and semantic information of the data, and make final predictions through fully connected layers.
It improves the accuracy and robustness of music genre classification, can better handle music data with diverse music styles and large amounts of data, and provides more accurate classification performance.
Smart Images

Figure CN118538245A
Abstract
Description
Technical Field
[0001] The present invention provides a method for classifying music genres and constructing the method based on ResNet18 and Transformer dual branches. Background Art
[0002] With the popularization of digital music and the development of the Internet, a large number of music works and related information have been digitized and stored on various platforms. Since different users on each platform have different preferences for music, music information retrieval can make it easier to find music works that suit their tastes based on their personal interests and preferences. Music information retrieval includes music genre classification, instrument classification, automatic labeling, music emotion recognition, and music similarity analysis. Among the many tasks, music genre classification is one of the important tasks. It is classified according to factors such as the style, characteristics, and creative background of music works. Common music genres include classical music, pop music, rock, etc. These are just some common examples of music genre classification. In fact, music genres are very rich and diverse, and each genre has its own unique music style and characteristics. Being able to accurately classify music works into genres helps to organize and manage music libraries and provide more accurate music recommendations and search results.
[0003] In recent years, many researchers have used machine learning and deep learning methods to classify music genres. For example, they use machine learning or deep learning algorithms, such as convolutional neural networks (CNN), random forests (RF), long short-term memory (LSTM), etc., to model and classify the extracted hand-crafted features. Classification based on hand-crafted features will make it difficult to capture higher-level abstract features and semantic information in music, and cannot fully express the diversity and personality of music. Therefore, when faced with new music samples or different genres, hand-crafted features may not provide accurate and robust classification performance.
[0004] In summary, although the above methods have achieved some good results, they still have certain limitations when dealing with data with varied music styles, large amounts of music data, and diverse music features. Summary of the invention
[0005] The present invention is a method for classifying music genres and constructing it based on ResNet18 and Transformer dual branches, which is used to solve the problems of limitations in predicting and classifying music data with diverse music styles, large amount of music data and incomplete features.
[0006] A method for classifying music genres and constructing the method based on ResNet18 and Transformer dual branches, characterized by comprising:
[0007] Constructing a data enhancement layer, wherein the data enhancement layer divides the input original data into segments of equal length to obtain more data with the same label as the original audio;
[0008] Constructing a Mel-spectrogram feature extraction layer, wherein the Mel-spectrogram feature extraction layer inputs the data-enhanced audio into the librosa library to extract global contour information and obtain a feature vector;
[0009] Constructing an extraction SincNet feature layer, wherein the extraction SincNet feature layer inputs the data-enhanced audio into three SincNet filters of different lengths to extract global spectrum information and obtain a feature vector;
[0010] Construct a Transformer Encoder layer, which inputs the output of the Patch Embedding layer into the Transformer Encoder layer and outputs a tensor for subsequent concatenation with the output of ResNet18;
[0011] Construct a ResNet18 layer, which extracts the output of the SincNet feature layer and inputs it into the ResNet18 layer. This layer also outputs a tensor, which is subsequently concatenated with the output of the Transformer Encoder.
[0012] A fully connected layer is constructed, which converts the tensor concatenation results output by the Transformer Encoder layer and the ResNet18 layer into the final prediction result.
[0013] In a specific implementation, the steps of constructing the data enhancement layer include:
[0014] Initialize the original audio data and sample the input audio data in equal length segments. The specific method is to randomly sample the original audio data at five non-overlapping random positions within three consecutive seconds. (Sampling rate (sr) = 22050)
[0015] In a specific embodiment, the step of constructing and extracting a Mel-frequency spectrum feature layer includes:
[0016] (1) Loading audio data
[0017] (2) Calculate the short-time Fourier transform (STFT)
[0018] (3) Calculate the power spectrum
[0019] (4) Convert to Mel-spectrogram
[0020]
[0021] where S(m,t) is the mth Mel-band power in the tth frame, |X(m,k,t)| 2 is the power spectrum of the kth frequency in the tth frame, and H(m,k) is the response of the mth Mel filter at the kth frequency. The power of all Mel frequency bands in each time frame is sorted out to obtain the final Mel spectrum map M.
[0022] In a specific embodiment, the construction and extraction of the SincNet feature layer includes:
[0023] (1) One-dimensional kernel learning is performed by three SincNet filters with lengths of 251, 501, and 1001 respectively. The frequency response formula of the matrix low-pass filter is as follows:
[0024]
[0025] By performing Fourier transform on the filter function G, we can get the impulse response of the filter, expressed as a sinc function:
[0026] g f1,f2 [n]=2f2sinc(2πf2n)-2f1sinc(2πf1n)
[0027] n=1,2,...,L
[0028] Where L is the filter length and the sinc function is defined as:
[0029] sinc(x)=sin(x) / x
[0030] (2) Adaptive average pooling to obtain three-channel two-dimensional SincNet features
[0031] In a specific implementation, the constructing of the Transformer Encoder layer includes:
[0032] The Transformer Encoder layer is mainly composed of 5 steps, and the specific algorithm steps are:
[0033] (1) Embedding layer: In the Transformer Encoder, the Mel-spectrogram is used as the input sequence and is first encoded through an embedding layer. Therefore, after embedding, M becomes M embedding
[0034] (2) Position encoding: Since the Mel-spectrogram is time series data, it lacks explicit position information. In order to introduce the time order information, position encoding is added to the embedded Mel-spectrogram. In this paper, the sine and cosine functions are used for marking:
[0035]
[0036] Where pos represents the position of the word in the sentence, and i refers to the dimension of the word vector.
[0037] (3) Multi-head self-attention mechanism: The Transformer Encoder uses a multi-head self-attention mechanism to model the Mel-spectrogram. The multi-head self-attention mechanism can capture the dependencies between different positions in the sequence, which can be understood as calculating correlation. The self-attention method is used here. embedding To generate Query, Key, Value, the specific calculation process is as follows:
[0038] Q=M embedding *W Q
[0039] K=M embedding *W K
[0040] V=M embedding *W V
[0041] Next, we calculate the attention mechanism. According to the fact that the larger the dot product of two vectors, the more similar they are, we use QK T Find the attention matrix, and then weight the Value according to the attention matrix, that is,
[0042]
[0043] in In order to transform the attention matrix into a standard normal distribution, softmax is normalized so that the sum of the attention weights of each word and other words is 1. This operation makes the embedding of each word contain the information of all words in the current sentence. Note that the dimension of Attention(Q,K,V) is consistent with the dimension of V.
[0044] (4) Feedforward Neural Network: A feedforward neural network is a fully connected forward propagation network used to perform nonlinear transformation and deep representation learning on the feature representation of each time step.
[0045] (5) Layer normalization and residual connection: Layer normalization is used to normalize features after each sublayer to speed up the training process. The specific operation is to subtract the mean of each row from each element of each row, and then divide it by the standard deviation of the row to obtain the normalized value. Residual connection allows information to be directly transferred between different layers through skip connections, which helps information flow and gradient propagation.
[0046] In a specific implementation, the construction of the ResNet18 layer includes:
[0047] Building the ResNet18 layer mainly consists of 5 steps, the specific algorithm steps are:
[0048] (1) Accept sincNet features
[0049] (2) Initialize the convolutional layer
[0050] (3) Residual Block, ResNet18 consists of 4 stages, each stage contains 2 residual blocks. Each residual block consists of two 3x3 convolutional layers and a skip connection. At the beginning of each stage, a convolutional layer with a stride of 2 is used to change the size of the feature map.
[0051] (4) Global Average Pooling,After the last residual block, a global average pooling layer is used to aggregate features.
[0052] (5) Fully connected layer
[0053] In a specific embodiment, constructing a fully connected layer includes:
[0054] Building a fully connected layer mainly consists of 5 steps, the specific steps are as follows:
[0055] (1) Concatenate the tensors output by the Transformer Encoder layer and the ResNet18 layer
[0056] (2) Weight matrix multiplication. Perform matrix multiplication on the input feature vector and the weight matrix W.
[0057] (3) Bias addition
[0058] (4) Activation function
[0059] (5) Output the final classification results
[0060] The present invention discloses a method for classifying music genres and constructing the method based on ResNet18 and Transformer dual branches, and constructs a data enhancement layer. In order to make the input data more robust and increase the amount of data, each audio clip in the original data set is randomly sampled at five non-overlapping random positions in a continuous 3-second window, so that a 3s clip audio with the same original label can be obtained; after obtaining the 3s clip data, the data is divided into two branches, which are respectively input into a Mel spectrum graph feature extraction layer and a SincNet feature extraction layer; the enhanced data is subjected to the Mel spectrum graph feature extraction layer to obtain the extracted Mel spectrum graph features, and then the obtained Mel spectrum graph features are input into a Transformer Encoder layer, and a tensor is obtained through embedding, encoding, attention calculation, feedforward neural network, layer normalization and residual of the Transformer Encoder layer; the enhanced data is subjected to the extraction of SincNet features to obtain three-channel two-dimensional features, and the features are input into a ResNet18 layer, and a tensor is also obtained through ResNet18 convolution, residual and average pooling; the Transformer The tensor output by the Encoder layer is concatenated with the tensor output by the ResNet18 layer, and finally the final classification is performed. Compared with other models, the present invention can be used to solve the problem of limitations in the prediction and classification of music data with diverse music styles, large amounts of music data, and diverse music features. It provides a new idea for solving the classification of music genres in the future. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 The present invention is a flowchart of a method for classifying music genres and constructing the same based on ResNet18 and Transformer dual branches;
[0062] Figure 2 It is a schematic diagram of the overall structure of the music genre classification model based on ResNet18 and Transformer dual branches of the present invention;
[0063] Figure 3 This is a SincNet feature structure diagram extracted from the music genre classification model based on the ResNet18 and Transformer dual branches of the present invention. DETAILED DESCRIPTION
[0064] The present invention is an embodiment of a method for classifying music genres and constructing the same based on ResNet18 and Transformer dual branches:
[0065] This embodiment provides a method for classifying music genres and constructing it based on ResNet18 and Transformer dual branches. The hardware execution subject of the construction method can be a desktop computer, a laptop computer, a server device, an intelligent mobile terminal (tablet computer, smart phone, etc.), etc., which is not limited in this embodiment.
[0066] like Figure 1 As shown, the construction method includes:
[0067] Step 1: Construct a data enhancement layer, which divides the input original data into equal-length segments to obtain more data with the same label as the original audio. The specific steps include:
[0068] Initialize the original audio data and sample the input audio data in equal length segments. The specific method is to randomly sample the original audio data at five non-overlapping random positions within three consecutive seconds. (Sampling rate (sr) = 22050)
[0069] Step 2: Construct a data enhancement layer, which divides the input original data into segments of equal length to obtain more data with the same label as the original audio. The specific operation steps include:
[0070] (1) Loading audio data
[0071] (2) Calculate the short-time Fourier transform (STFT)
[0072] (3) Calculate the power spectrum
[0073] (4) Convert to Mel-spectrogram
[0074]
[0075] where S(m,t) is the mth Mel-band power in the tth frame, |X(m,k,t)| 2 is the power spectrum of the kth frequency in the tth frame, and H(m,k) is the response of the mth Mel filter at the kth frequency. The power of all Mel frequency bands in each time frame is sorted out to obtain the final Mel spectrum map M.
[0076] Step 3: Construct an extraction SincNet feature layer. The extraction SincNet feature layer is to input the data-enhanced audio into three SincNet filters of different lengths to extract global spectrum information and obtain a feature vector. The specific operation steps include:
[0077] (1) One-dimensional kernel learning is performed by three SincNet filters with lengths of 251, 501, and 1001 respectively. The frequency response formula of the matrix low-pass filter is as follows:
[0078]
[0079] By performing Fourier transform on the filter function G, we can get the impulse response of the filter, expressed as a sinc function:
[0080] g f1,f2 [n]=2f2sinc(2πf2n)-2f1sinc(2πf1n)
[0081] n=1,2,...,L
[0082] Where L is the filter length and the sinc function is defined as:
[0083] sinc(x)=sin(x) / x
[0084] (2) Adaptive average pooling to obtain three-channel two-dimensional SincNet features
[0085] Step 4: Construct a Transformer Encoder layer, which inputs the output of the PatchEmbedding layer into the Transformer Encoder layer and outputs a tensor for subsequent concatenation with the output of ResNet18. The specific steps include:
[0086] The Transformer Encoder layer is mainly composed of 5 steps, and the specific algorithm steps are:
[0087] (1) Embedding layer: In the Transformer Encoder, the Mel-spectrogram is used as the input sequence and is first encoded through an embedding layer. Therefore, after embedding, M becomes M embedding
[0088] (2) Position encoding: Since the Mel-spectrogram is time series data, it lacks explicit position information. In order to introduce the time order information, position encoding is added to the embedded Mel-spectrogram. In this paper, the sine and cosine functions are used for marking:
[0089]
[0090] Where pos represents the position of the word in the sentence, and i refers to the dimension of the word vector.
[0091] (3) Multi-head self-attention mechanism: The Transformer Encoder uses a multi-head self-attention mechanism to model the Mel-spectrogram. The multi-head self-attention mechanism can capture the dependencies between different positions in the sequence, which can be understood as calculating correlation. The self-attention method is used here. embedding To generate Query, Key, Value, the specific calculation process is as follows:
[0092] Q=M embedding *W Q
[0093] K=M embedding *W K
[0094] V=M embedding *W V
[0095] Next, we calculate the attention mechanism. According to the fact that the larger the dot product of two vectors, the more similar they are, we use QK T Find the attention matrix, and then weight the Value according to the attention matrix, that is,
[0096]
[0097] in In order to transform the attention matrix into a standard normal distribution, softmax is normalized so that the sum of the attention weights of each word and other words is 1. This operation makes the embedding of each word contain the information of all words in the current sentence. Note that the dimension of Attention(Q,K,V) is consistent with the dimension of V.
[0098] (4) Feedforward Neural Network: A feedforward neural network is a fully connected forward propagation network used to perform nonlinear transformation and deep representation learning on the feature representation of each time step.
[0099] (5) Layer normalization and residual connection: Layer normalization is used to normalize features after each sublayer to speed up the training process. The specific operation is to subtract the mean of each row from each element of each row, and then divide it by the standard deviation of the row to obtain the normalized value. Residual connection allows information to be directly transferred between different layers through skip connections, which helps information flow and gradient propagation.
[0100] Step 5: Construct the ResNet18 layer. The ResNet18 layer extracts the output result of the SincNet feature layer and inputs it into the ResNet18 layer. This layer also outputs a tensor, which is subsequently spliced with the output of the Transformer Encoder. The specific operation steps include:
[0101] Building the ResNet18 layer mainly consists of 5 steps, the specific algorithm steps are:
[0102] (1) Accept sincNet features
[0103] (2) Initialize the convolutional layer
[0104] (3) Residual Block, ResNet18 consists of 4 stages, each stage contains 2 residual blocks. Each residual block consists of two 3x3 convolutional layers and a skip connection. At the beginning of each stage, a convolutional layer with a stride of 2 is used to change the size of the feature map.
[0105] (4) Global Average Pooling,After the last residual block, a global average pooling layer is used to aggregate features.
[0106] (5) Fully connected layer
[0107] Step 6: Construct a fully connected layer, which converts the tensor concatenation results output by the Transformer Encoder layer and the ResNet18 layer into the final prediction result. The specific operation steps include:
[0108] Building a fully connected layer mainly consists of 5 steps, the specific steps are as follows:
[0109] (1) Concatenate the tensors output by the Transformer Encoder layer and the ResNet18 layer
[0110] (2) Weight matrix multiplication. Perform matrix multiplication on the input feature vector and the weight matrix W.
[0111] (3) Bias addition
[0112] (4) Activation function
[0113] (5) Output the final classification results
[0114] Figure 3 This is a SincNet feature structure diagram extracted from the music genre classification model based on the ResNet18 and Transformer dual branches of the present invention.
[0115] The above embodiment only illustrates the technical solution of the present invention in a specific implementation mode. Any equivalent substitution of the present invention and any modification or partial substitution that does not depart from the spirit and scope of the present invention should be included in the scope of protection of the claims of the present invention.
Claims
1. A method for classifying music genres and constructing it based on ResNet18 and Transformer dual branches, characterized in that: include: Constructing a data enhancement layer, wherein the data enhancement layer divides the input original data into segments of equal length to obtain more data with the same label as the original audio; Constructing a Mel-spectrogram feature extraction layer, wherein the Mel-spectrogram feature extraction layer inputs the data-enhanced audio into the librosa library to extract global contour information and obtain a feature vector; Constructing an extraction SincNet feature layer, wherein the extraction SincNet feature layer inputs the data-enhanced audio into three SincNet filters of different lengths to extract global spectrum information and obtain a feature vector; Construct a Transformer Encoder layer, which inputs the output of the Patch Embedding layer into the Transformer Encoder layer and outputs a tensor for subsequent concatenation with the output of ResNet18; Construct a ResNet18 layer, which extracts the output of the SincNet feature layer and inputs it into the ResNet18 layer. This layer also outputs a tensor, which is subsequently concatenated with the output of the Transformer Encoder. A fully connected layer is constructed, which converts the tensor concatenation results output by the Transformer Encoder layer and the ResNet18 layer into the final prediction result.
2. The method for classifying music genres and constructing the extracted audio features based on ResNet18 and Transformer dual branches according to claim 1 is characterized in that: Constructing the data enhancement layer, the specific steps include: Initialize the original audio data and sample the input audio data into segments of equal length, by randomly sampling the original audio data at five non-overlapping random positions within three consecutive seconds (sampling rate (sr) = 22050).
3. The method for classifying music genres and constructing the extracted audio features based on ResNet18 and Transformer dual branches according to claim 1 is characterized in that: Construct the Mel-spectrogram feature layer, including: (1) Loading audio data (2) Calculate the short-time Fourier transform (STFT) (3) Calculate the power spectrum (4) Convert to Mel-spectrogram where S(m,t) is the mth Mel-band power in the tth frame, |X(m,k,t)| 2 is the power spectrum of the kth frequency in the tth frame, and H(m,k) is the response of the mth Mel filter at the kth frequency. The power of all Mel frequency bands in each time frame is sorted out to obtain the final Mel spectrum map M.
4. The method for classifying music genres and constructing the extracted audio features based on ResNet18 and Transformer dual branches according to claim 1 is characterized in that: Construct and extract SincNet feature layers, including: (1) One-dimensional kernel learning is performed by three SincNet filters with lengths of 251, 501, and 1001 respectively. The frequency response formula of the matrix low-pass filter is as follows: By performing Fourier transform on the filter function G, we can get the impulse response of the filter, expressed as a sinc function: g f1,f2 [n]=2f2sinc(2πf2n)-2f1sinc(2πf1n) n=1,2,...,L Where L is the filter length and the sinc function is defined as: sinc(x)=sin(x) / x (2) Adaptive average pooling to obtain three-channel two-dimensional SincNet features.
5. The method for classifying music genres and constructing the extracted audio features based on ResNet18 and Transformer dual branches according to claim 1 is characterized in that: Construct the extractor TransformerEncoder layer, including: The Transformer Encoder layer is mainly composed of 5 steps, and the specific algorithm steps are: (1) Embedding layer: In the Transformer Encoder, the Mel-spectrogram is used as the input sequence and is first encoded through an embedding layer. Therefore, after embedding, M becomes M embedding (2) Position encoding: Since the Mel-spectrogram is time series data, it lacks explicit position information. In order to introduce the time order information, position encoding is added to the embedded Mel-spectrogram. In this paper, the sine and cosine functions are used for marking: Where pos represents the position of the word in the sentence, and i refers to the dimension of the word vector. (3) Multi-head self-attention mechanism: The Transformer Encoder uses a multi-head self-attention mechanism to model the Mel-spectrogram. The multi-head self-attention mechanism can capture the dependencies between different positions in the sequence, which can be understood as calculating correlation. The self-attention method is used here. embedding To generate Query, Key, Value, the specific calculation process is as follows: Q=M embedding *W Q K=M embedding *W K V=M embedding *W V Next, we calculate the attention mechanism. According to the fact that the larger the dot product of two vectors, the more similar they are, we use QK T Find the attention matrix, and then weight the Value according to the attention matrix, that is, in In order to transform the attention matrix into a standard normal distribution, softmax is normalized so that the sum of the attention weights of each word and other words is 1. This operation makes the embedding of each word contain the information of all words in the current sentence. Note that the dimension of Attention(Q,K,V) is consistent with the dimension of V. (4) Feedforward Neural Network: A feedforward neural network is a fully connected forward propagation network used to perform nonlinear transformation and deep representation learning on the feature representation of each time step. (5) Layer normalization and residual connection: Layer normalization is used to normalize features after each sublayer to speed up the training process. The specific operation is to subtract the mean of each row from each element of each row, and then divide it by the standard deviation of the row to obtain the normalized value. Residual connection allows information to be directly transferred between different layers through skip connections, which helps information flow and gradient propagation.
6. The method for classifying music genres and constructing the extracted audio features based on ResNet18 and Transformer dual branches according to claim 1, characterized in that: Build and extract the ResNet18 layer, including: Building the ResNet18 layer mainly consists of 5 steps, the specific algorithm steps are: (1) Accept sincNet features (2) Initialize the convolutional layer (3) Residual Block, ResNet18 consists of 4 stages, each stage contains 2 residual blocks. Each residual block consists of two 3x3 convolutional layers and a skip connection. At the beginning of each stage, A convolutional layer with a stride of 2 is used to change the size of the feature map. (4) Global Average Pooling,After the last residual block, a global average pooling layer is used to aggregate features. (5) Fully connected layer.
7. The method for classifying music genres and constructing the extracted audio features based on ResNet18 and Transformer dual branches according to claim 1, characterized in that: Construct a fully connected layer, including: Building a fully connected layer mainly consists of 5 steps, the specific steps are as follows: (1) Concatenate the tensors output by the Transformer Encoder layer and the ResNet18 layer (2) Weight matrix multiplication. Perform matrix multiplication on the input feature vector and the weight matrix W. (3) Bias addition (4) Activation function (5) Output the final classification result.
8. A method for classifying music genres and constructing it based on ResNet18 and Transformer dual branches, characterized in that: include: Constructing a data enhancement layer, wherein the data enhancement layer divides the input original data into segments of equal length to obtain more data with the same label as the original audio; Constructing a Mel-spectrogram feature extraction layer, wherein the Mel-spectrogram feature extraction layer inputs the data-enhanced audio into the librosa library to extract global contour information and obtain a feature vector; Constructing an extraction SincNet feature layer, wherein the extraction SincNet feature layer inputs the data-enhanced audio into three SincNet filters of different lengths to extract global spectrum information and obtain a feature vector; Construct a Transformer Encoder layer, which inputs the output of the Patch Embedding layer into the Transformer Encoder layer and outputs a tensor for subsequent concatenation with the output of ResNet18; Construct a ResNet18 layer, which extracts the output of the SincNet feature layer and inputs it into the ResNet18 layer. This layer also outputs a tensor, which is subsequently concatenated with the output of the Transformer Encoder. A fully connected layer is constructed, which converts the tensor concatenation results output by the Transformer Encoder layer and the ResNet18 layer into the final prediction result.
9. The method for classifying music genres and constructing the extracted audio features based on ResNet18 and Transformer dual branches according to claim 8, characterized in that: Constructing the data enhancement layer, the specific steps include: Initialize the original audio data and sample the input audio data into segments of equal length, by randomly sampling the original audio data at five non-overlapping random positions within three consecutive seconds (sampling rate (sr) = 22050).
10. The method for classifying and constructing music genres based on extracted audio features based on ResNet18 and Transformer dual branches according to claim 8, characterized in that: Construct the Mel-spectrogram feature layer, including: (1) Loading audio data (2) Calculate the short-time Fourier transform (STFT) (3) Calculate the power spectrum (4) Convert to Mel-spectrogram where S(m,t) is the mth Mel-band power in the tth frame, |X(m,k,t)| 2 is the power spectrum of the kth frequency in the tth frame, and H(m,k) is the response of the mth Mel filter at the kth frequency. The power of all Mel frequency bands in each time frame is sorted out to obtain the final Mel spectrum map M.
11. The method for classifying music genres and constructing the extracted audio features based on ResNet18 and Transformer dual branches according to claim 8, characterized in that: Construct and extract the SincNet feature layer, including: (1) One-dimensional kernel learning is performed by three SincNet filters with lengths of 251, 501, and 1001 respectively. The frequency response formula of the matrix low-pass filter is as follows: By performing Fourier transform on the filter function G, we can get the impulse response of the filter, expressed as a sinc function: g f1,f2 [n]=2f2sinc(2πf2n)-2f1sinc(2πf1n) n=1,2,...,L Where L is the filter length and the sinc function is defined as: sinc(x)=sin(x) / x (2) Adaptive average pooling to obtain three-channel two-dimensional SincNet features.
12. The method for classifying and constructing music genres based on extracted audio features based on ResNet18 and Transformer dual branches according to claim 8, characterized in that: Construct the extractor TransformerEncoder layer, including: The Transformer Encoder layer is mainly composed of 5 steps, and the specific algorithm steps are: (1) Embedding layer: In the Transformer Encoder, the Mel-spectrogram is used as the input sequence and is first encoded through an embedding layer. Therefore, after embedding, M becomes M embedding (2) Position encoding: Since the Mel-spectrogram is time series data, it lacks explicit position information. In order to introduce the time order information, position encoding is added to the embedded Mel-spectrogram. In this paper, the sine and cosine functions are used for marking: Where pos represents the position of the word in the sentence, and i refers to the dimension of the word vector. (3) Multi-head self-attention mechanism: The Transformer Encoder uses a multi-head self-attention mechanism to model the Mel-spectrogram. The multi-head self-attention mechanism can capture the dependencies between different positions in the sequence, which can be understood as calculating correlation. The self-attention method is used here. embedding To generate Query, Key, Value, the specific calculation process is as follows: Q=M embedding *W Q K=M embedding *W K V=M embedding *W V Next, we calculate the attention mechanism. According to the fact that the larger the dot product of two vectors, the more similar they are, we use QK T Find the attention matrix, and then weight the Value according to the attention matrix, that is, in In order to transform the attention matrix into a standard normal distribution, softmax is normalized so that the sum of the attention weights of each word and other words is 1. This operation makes the embedding of each word contain the information of all words in the current sentence. Note that the dimension of Attention(Q,K,V) is consistent with the dimension of V. (4) Feedforward Neural Network: A feedforward neural network is a fully connected forward propagation network used to perform nonlinear transformation and deep representation learning on the feature representation of each time step. (5) Layer normalization and residual connection: Layer normalization is used to normalize features after each sublayer to speed up the training process. The specific operation is to subtract the mean of each row from each element of each row, and then divide it by the standard deviation of the row to obtain the normalized value. Residual connection allows information to be directly transferred between different layers through skip connections, which helps information flow and gradient propagation.
13. The method for classifying music genres and constructing the extracted audio features based on ResNet18 and Transformer dual branches according to claim 8, characterized in that: Build and extract the ResNet18 layer, including: Building the ResNet18 layer mainly consists of 5 steps, the specific algorithm steps are: (1) Accept sincNet features (2) Initialize the convolutional layer (3) Residual Block, ResNet18 consists of 4 stages, each stage contains 2 residual blocks. Each residual block consists of two 3x3 convolutional layers and a skip connection. At the beginning of each stage, a convolutional layer with a stride of 2 is used to change the size of the feature map. (4) Global Average Pooling,After the last residual block, a global average pooling layer is used to aggregate features. (5) Fully connected layer.
14. The method for classifying and constructing music genres based on extracted audio features based on ResNet18 and Transformer dual branches according to claim 8, characterized in that: Construct a fully connected layer, including: Building a fully connected layer mainly consists of 5 steps, the specific steps are as follows: (1) Concatenate the tensors output by the Transformer Encoder layer and the ResNet18 layer (2) Weight matrix multiplication. Perform matrix multiplication on the input feature vector and the weight matrix W. (3) Bias addition (4) Activation function (5) Output the final classification result.
Citation Information
Cited By
Music genre classification method and device based on self-supervision and mixed attention mechanism
CN119832883A
