I am using lstm regression network to denoise speech. The predictor input consists of 9 consecutive noisy STFT vectors. The target is corresponding clean STFT vector. The length of each vector is 129. Here 's the network I defined: layers = [ sequenceInputLayer([129 9 1],"Name","sequence") flattenLayer("Name","flatten") lstmLayer(128,"Name","lstm") fullyConnectedLayer(129,"Name","fc_1") reluLayer("Name","relu") fullyConnectedLayer(129,"Name","fc_2") regressionLayer("Name","regressionoutput")]; I trained the network with X and Y of sizes: size(X): 129 9 1 254829 size(Y): 129 254829 I got the error "Invalid training data. X and Y must have the same number of observations". I think that maybe the network I defined is wrong. I am new with lstm network to do sequence-to-sequence regression. What should I do with my network or training data?
Prashant Kumar answered .
2025-11-20
It sounds like you're encountering an issue with mismatched dimensions between your input data (X) and target data (Y). This is a common issue when working with sequence-to-sequence models. Here are a few steps to help you troubleshoot and resolve this error:
1. Verify Data Dimensions: Ensure that the number of observations in X and Y are the same. For example, if X has 100 observations, Y should also have 100 observations.
2. Check Data Format: For sequence-to-sequence regression, your target data (Y) should be in the same format as your input data (X). If X is a sequence, Y should also be a sequence of the same length.
3. Network Configuration: Ensure your network is configured correctly for sequence-to-sequence regression. Here's an example of how you might define your network:
layers = [
sequenceInputLayer(inputSize, 'Name', 'input')
lstmLayer(numHiddenUnits, 'Name', 'lstm')
fullyConnectedLayer(outputSize, 'Name', 'fc')
regressionLayer('Name', 'regression')
];
4. Training Data Format: When training the network, ensure that your input data (X) and target data (Y) are in the correct format. For example:
options = trainingOptions('adam', ...);
net = trainNetwork(X, Y, layers, options);
5. Example Code: Here's a simple example to illustrate the correct format:
% Example data
X = rand(100, 10, 1); % 100 sequences, each with 10 time steps
Y = rand(100, 10, 1); % 100 sequences, each with 10 time steps
% Define the network
layers = [
sequenceInputLayer([10 1], 'Name', 'input')
lstmLayer(128, 'Name', 'lstm')
fullyConnectedLayer(1, 'Name', 'fc')
regressionLayer('Name', 'regression')
];
% Train the network
options = trainingOptions('adam', ...);
net = trainNetwork(X, Y, layers, options);
Make sure your input data (X) and target data (Y) have the same number of sequences and each sequence has the same length.