trainNetwork error RESHAPE line 260

2 ビュー (過去 30 日間)
Elaine Todd
Elaine Todd 2020 年 2 月 7 日
回答済み: Sourav Bairagya 2020 年 2 月 12 日
Hi! I'm trying to make a classification network, but I keep running into an error in trainNetwork and I'm having a hard time figuring it out. This is the error I'm getting
Error using trainNetwork (line 170)
To RESHAPE the number of elements must not change.
Error in train2 (line 7)
trained_net = trainNetwork(X,Y,layers,options);
Error in Crashworthiness_NN (line 24)
trained_net = train2(X,Y, layers);
Caused by:
Error using reshape
To RESHAPE the number of elements must not change.
Using the debugging tool I've realized that the code runs until line 260 trainedNet = trainer.train(trainedNet, trainingDispatcher); during the call from line 170. I'm not sure what I'm doing wrong. Here is the code I have
layers = [sequenceInputLayer([100,5,1])
flattenLayer
bilstmLayer(100)
fullyConnectedLayer(10)
reluLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
trained_net = train2(X,Y, layers);
function trained_net = train2(X,Y, layers)
% creates adam optimizer
options = trainingOptions('adam', 'InitialLearnRate',3e-4, ...
'SquaredGradientDecayFactor',0.99, 'MaxEpochs',20, ...
'MiniBatchSize',10, 'Plots','training-progress');
% trains network
trained_net = trainNetwork(X,Y,layers,options);
where X is a 100x5 double and Y is a 100x1 categorical. I'm new to the deeplearning toolbox so I'm not 100% how everything works so this may be a simple mistake but I can't figure it out.
Thanks!

回答 (1 件)

Sourav Bairagya
Sourav Bairagya 2020 年 2 月 12 日
It seems that the error lies in using 'reshape' function in 'Crashworthiness_NN'. It may be possible that the number of elements in the input of the 'reshape' is not equal to the number of elements in output. It will be good to check the dimensions of input and output once.

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by