MATLAB Answers

Sequence by Sequence response

10 views (last 30 days)
Hi,
i am trying to do something exactly same as this but using data stores. So i am following this example.
In the Japanese vowels example, there is one label for a 20 second data [12*20]. My responses are same as the HumanActivity example. so for each second i have a separate response. My x_train is [25*2560] and y_train is categorical [1*2560]. the response is 0 for absence and 1 is for presence.
when i try to run this i face this error:
Error using trainNetwork (line 165)
Unexpected response size: The output layer expects responses with the same sequence length and feature dimension 2.
Error in Main (line 55)
net = trainNetwork(cdsTrain,layers,options);
This is my code:
% Read all files to datastores
x_train = fileDatastore('D:\x_train',...
'ReadFcn',@load);
x_test = fileDatastore('D:\x_test',...
'ReadFcn',@load);
train_target = fileDatastore('D:\y_train',...
'ReadFcn',@load);
test_target = fileDatastore('D:\y_test',...
'ReadFcn',@load);
%% Set your limit (30 seconds with 256 Sampling rate)
Fs=256;
Lim=Fs*30;
sequenceLength = Lim;
tdsTrain = transform(x_train,@(data) padSequence(data,sequenceLength));
tdsLabels = transform(train_target,@(data) padSequence2(data,sequenceLength));
%% combine the predictor and response
cdsTrain = combine(tdsTrain,tdsLabels);
%% Network design
numFeatures = 25;
numClasses = 2;
numHiddenUnits = 100;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits,'OutputMode','sequence')
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
miniBatchSize = 32;
options = trainingOptions('adam', ...
'ExecutionEnvironment','gpu', ...
'MaxEpochs',20, ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',2, ...
'Shuffle','never',...
'Verbose',0, ...
'Plots','training-progress');
%%
net = trainNetwork(cdsTrain,layers,options);
The Japanese vowels example has this format:
1×2 cell array
{12×20 double} {[1]}
My data:
1×2 cell array
{25×7680 double} {1×7680 categorical}

  2 Comments

Vimal Rathod
Vimal Rathod on 23 Jul 2019
Hey,
Could you send some part of your training data, if not your full data so that I could know more about the format and other aspects. I suspect there is some problem with your input data.
Kiyan Afsari
Kiyan Afsari on 23 Jul 2019
Hi,
My data is similar to the HumanActivty on matlab.
x_train is 24*307200 double
corresponding label is stored 1*307200 categorical

Sign in to comment.

Accepted Answer

Vimal Rathod
Vimal Rathod on 26 Jul 2019
Hey,
I used your same code and added a line after the 10th line which is used for transforming tdsTrain data and it works!
Here is the line I have added.
ytrainDs = transform(ytrainDs,@(data) padSequence(data,sequenceLength));

  1 Comment

Kiyan Afsari
Kiyan Afsari on 26 Jul 2019
FANTASTIC ! It works perfectly ! Thanks a ton!

Sign in to comment.

More Answers (1)

Vimal Rathod
Vimal Rathod on 25 Jul 2019
The input data looks fine, but I suspect that there might be an error in the padSequence2 function which is not a helper function defined in MATLAB. If it is defined by you, there might be an error in the size of the labels sequence the function is returning(As shown in the error) the padSequence2 function returns or else that might be the typing mistake.

  1 Comment

Kiyan Afsari
Kiyan Afsari on 25 Jul 2019
Yes that is another function that loads the file with a different name, there is no issues in this code actually i ac run this with no issues if the lable is 1 per file. But my problem is i have 1 label per sample of the file. So for x_train of 23*1250 i have a label array of 1*1250.
You can simply open the m file preprocess and train.
Have a look at my 3 predictors (x_trains) and my 3 labels (y_train) if possible:
Thank you for your time not everybody looked at the question !

Sign in to comment.

Sign in to answer this question.

Products


Release

R2019a

Translated by