- trainnet - https://www.mathworks.com/help/deeplearning/ref/trainnet.html
- predict - https://www.mathworks.com/help/deeplearning/ref/dlnetwork.predict.html
- training options - https://www.mathworks.com/help/deeplearning/ref/trainingoptions.html
- Deep Learning data formats - https://www.mathworks.com/help/deeplearning/ug/deep-learning-data-formats.html
- sequenceInputLayer - https://www.mathworks.com/help/deeplearning/ref/nnet.cnn.layer.sequenceinputlayer.html
InputSize definition for sequenceInputLayer for multidimensional time sequences
12 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to input data to a LSTM network using a sequenceInputLayer. The input data is a cell array with dimensions 6766x1, in which, each cell is a 3D tensor of dimensions 1024 x numOfTimeSteps x 2. Each rows x depth slice is a time step, and the numOfTimeSteps is variable between each cell. It is not clear how the property InputSize should be set in this case, as I am dealing with a vector sequence but one that is multidimensional and of variable length between cells.
Any thoughts?
Thanks,
Jacopo
0 个评论
采纳的回答
Paras Gupta
2024-7-18
Hi Jacopo,
I understand that you are trying to input data to an LSTM network using a "sequenceInputLayer". Your input data is a cell array with dimensions 6766x1, where each cell is a 3D tensor of dimensions 1024 x numOfTimeSteps x 2.
For the "sequenceInputLayer", the "InputSize" should be set to the size of each time step. In your case, each time step is a 2D slice of size [1024, 2], which will be the input size for the "sequenceInputLayer". Additionally, while training and inference, you need to consider the 'STCB' (Sequence, Time, Channel, Batch) data format for input data.
The following example code illustrates the use of "sequenceInputLayer" for your use-case:
% Define parameters
numSequences = 6766;
maxNumTimeSteps = 50;
inputSize = [1024, 2];
numHiddenUnits = 100;
numResponses = inputSize(2);
% Generate dummy data
data = cell(numSequences, 1);
taregt = cell(numSequences, 1);
for i = 1:numSequences
numTimeSteps = randi([1, maxNumTimeSteps]); % Random number of time steps
data{i} = randn(inputSize(1), numTimeSteps, inputSize(2)); % Random 3D tensor
target{i} = rand(numResponses, numTimeSteps) % random target data
end
% Define the network
layers = [
sequenceInputLayer(inputSize)
lstmLayer(128)
fullyConnectedLayer(numResponses)];
% Define training options
options = trainingOptions("adam", ...
InputDataFormats="STCB",...
TargetDataFormats="CTB",...
MaxEpochs=1, ...
Plots="training-progress");
% Train the network
net = trainnet(data, target, layers, 'mse', options);
% Pass input and make prediction
pred = predict(net, ones(1024, 40, 2), InputDataFormats="STCB", OutputDataFormats="CTB");
Please refer to the following documentation links for more information on the functions and data formats use in the code above:
Hope this helps you move forward with your work.
0 个评论
更多回答(1 个)
另请参阅
类别
在 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!