Sequence by Sequence response

4 views (last 30 days)
Kiyan Afsari
Kiyan Afsari on 13 Jul 2019
Commented: Kiyan Afsari on 26 Jul 2019
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',...
x_test = fileDatastore('D:\x_test',...
train_target = fileDatastore('D:\y_train',...
test_target = fileDatastore('D:\y_test',...
%% Set your limit (30 seconds with 256 Sampling rate)
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 = [ ...
miniBatchSize = 32;
options = trainingOptions('adam', ...
'ExecutionEnvironment','gpu', ...
'MaxEpochs',20, ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',2, ...
'Verbose',0, ...
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}
Kiyan Afsari
Kiyan Afsari on 23 Jul 2019
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
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.




Community Treasure Hunt

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

Start Hunting!