MATLAB Answers

trainNetwork error RESHAPE line 260

2 views (last 30 days)
Elaine Todd
Elaine Todd on 7 Feb 2020
Answered: Sourav Bairagya on 12 Feb 2020
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!

  0 Comments

Sign in to comment.

Answers (1)

Sourav Bairagya
Sourav Bairagya on 12 Feb 2020
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.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!