Sequence by Sequence response
8 ビュー (過去 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
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.
採用された回答
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
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.
参考
カテゴリ
Help Center および File Exchange で Language Support についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!