The training sequences are of feature dimension 60093 but the input layer expects sequences of feature dimension 39.
조회 수: 23 (최근 30일)
이전 댓글 표시
Hello everyone,
I am trying to implement LSTM on speech emotion recognition, I have a training matrix 60093*39 and test matrix 76503*39 with a sprerate label matrix of each of them, when I excuted the code below I got this error "The training sequences are of feature dimension 60093 but the input layer expects sequences of feature dimension 39", would anyone help me please, thanks in advance.
% Load the dataset
load('C:\Users\hamza\Desktop\deep_learning_matrix\matrice_mfcc_app.mat');
load('C:\Users\hamza\Desktop\deep_learning_matrix\matrice_mfcc_test.mat');
num_classes = 7;
% Transpose the training and test matrices
mfcc_matrix_app = mfcc_matrix_app'; % Transpose the training matrix
mfcc_matrix_test = mfcc_matrix_test'; % Transpose the test matrix
%featureSequences = HelperFeatureVector2Sequence(mfcc_matrix_app,20,5);
% Update the num_features variable with the correct value
num_features = size(mfcc_matrix_app, 2);
% Define the LSTM network architecture
num_hidden_units = 64;
layers = [
sequenceInputLayer(num_features)
lstmLayer(num_hidden_units, 'OutputMode', 'last')
fullyConnectedLayer(num_classes)
softmaxLayer
classificationLayer];
% Specify the training options
max_epochs = 20;
mini_batch_size = 128;
initial_learning_rate = 0.001;
options = trainingOptions('adam', ...
'MaxEpochs', max_epochs, ...
'MiniBatchSize', mini_batch_size, ...
'InitialLearnRate', initial_learning_rate, ...
'GradientThreshold', 1, ...
'Shuffle', 'every-epoch', ...
'Verbose', 1, ...
'Plots', 'training-progress');
% Train the LSTM network
net = trainNetwork(mfcc_matrix_app, CA, layers, options);
% Evaluate the performance of the trained model on the test data
predicted_labels = classify(net, mfcc_matrix_test);
accuracy = sum(predicted_labels == CT) / 7;
confusion_matrix = confusionmat(CT, predicted_labels);
disp(['Accuracy: ' num2str(accuracy)]);
disp('Confusion Matrix:');
disp(confusion_matrix);
Any help regarding this . I have this work space ... that may help you about the dimensions of data
댓글 수: 0
답변 (1개)
Shaik
2023년 5월 14일
Hi Hamza,
The error message you encountered indicates a mismatch between the feature dimensions of your training data and the input layer of the LSTM network. According to the error message, the training sequences have a feature dimension of 60093, while the input layer expects sequences of feature dimension 39.
To resolve this issue, you need to transpose your training and test matrices so that the features are correctly aligned. Here's how you can modify your code:
% Transpose the training and test matrices
mfcc_matrix_app = mfcc_matrix_app'; % Transpose the training matrix
mfcc_matrix_test = mfcc_matrix_test'; % Transpose the test matrix
% Update the num_features variable with the correct value
num_features = size(mfcc_matrix_app, 2);
% Define the LSTM network architecture
num_hidden_units = 64;
layers = [
sequenceInputLayer(num_features)
lstmLayer(num_hidden_units, 'OutputMode', 'last')
fullyConnectedLayer(num_classes)
softmaxLayer
classificationLayer];
% Rest of your code...
By transposing the matrices, you ensure that the features are represented along the correct dimension, which matches the input layer's expectation.
참고 항목
카테고리
Help Center 및 File Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!