Sequence by Sequence response

5 次查看(过去 30 天)
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 个评论
Vimal Rathod
Vimal Rathod 2019-7-23
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 2019-7-23
Hi,
My data is similar to the HumanActivty on matlab.
x_train is 24*307200 double
corresponding label is stored 1*307200 categorical

请先登录,再进行评论。

采纳的回答

Vimal Rathod
Vimal Rathod 2019-7-26
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 个)

Vimal Rathod
Vimal Rathod 2019-7-25
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 个评论
Kiyan Afsari
Kiyan Afsari 2019-7-25
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 !

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by