How to apply a 2D matrix input to a trainNetwork?

4 vues (au cours des 30 derniers jours)
vipin le 6 Sep 2023
Commenté : Joss Knight le 8 Sep 2023
I have the following piece of code for training a network:
layers = [
maxEpochs = 100;
options = trainingOptions('adam', ...
'ExecutionEnvironment','gpu', ...
'SequenceLength','longest', ...
'Shuffle','never', ...
net = trainNetwork(xt,yt,layers,options);
screenshot of a sample xt and yt is given below:
xt and yt
Basically each yt corresponds to a 3 by 5 matrix in xt. where 3 is the number of rows in the sequence and 5 is the number of features. Basically xt contains a sequence of stock prices - the 4 prices and volume, after scaling. yt corresponds to future close price.
I want to train the network with this. And I have tried various combinations, reshaping, converting it to cells etc. But its one error or the other.
Does someone know if its possible to do what I am trying to do? I am using version 2020b.
The current error is:
Error using trainNetwork (line 183)
The training sequences are of feature dimension 4 5 but the input layer expects sequences of feature dimension 5.

Réponses (1)

Joss Knight
Joss Knight le 8 Sep 2023
Typically sequence data is passed in as a cell array. In each cell you would be passing one sequence. If you want to pass a single numeric array then I think all you need to do is permute dims 1 and 2 - you have to put the features down the columns, i.e. each column is an observation. Arrangement is C-by-B-by-T.
  2 commentaires
Joss Knight
Joss Knight le 8 Sep 2023
Glad to hear an advocate for dlarray format labels!!
No, DAGNetwork APIs do not interact with dlarrays. They are for autodiff. Prepare yourself for upcoming R2023b to see that solution.
My understanding is that the intention is that you pass in a numeric array if you want to process a single sequence for inference, otherwise it's really intended that you use cell arrays. The documentation, in a noble attempt to provide information about every single possible kind of input data, says the data should be a
"c-by-s matrix, where c is the number of features of the sequence and s is the sequence length."
While the format of the responses for sequence-to-vector regression should be a
"Numeric row vector"
These are then put into cell arrays, one per observation.
Also, now that I look at it, the flatten layer doesn't seem right, and you'd need to unfold the sequence to pass through the fullyConnectedLayer. But shouldn't the lstmLayer be in OutputMode 'last' for that to work?
I guess I'll just defer to someone who knows more about sequence networks and stop interfering...

Connectez-vous pour commenter.


En savoir plus sur Image Data Workflows dans Help Center et File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by