Sequence by Sequence response
4 views (last 30 days)
Show older comments
Kiyan Afsari
on 13 Jul 2019
Commented: Kiyan Afsari
on 26 Jul 2019
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}
Accepted Answer
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));
More Answers (1)
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.
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!