train network error. reshape number of elements must not change. Use [] to automatically calculate the dimension size.

조회 수: 2 (최근 30일)
my input is a combined datastore of - 28x28 double input, and 1x1 categorical label.
layers = [
imageInputLayer([28 28 1],"Name","imageinput","Normalization","none")
fullyConnectedLayer(1,"Name","fc_2")
softmaxLayer("Name","softmax")
classificationLayer("Name","classoutput")];
miniBatchSize = 28;
options =
trainingOptions('adam', ...
'ExecutionEnvironment','cpu', ...
'MaxEpochs',84, ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',2, ...
'Shuffle','never',...
'Verbose',0, ...
'Plots','training-progress');
net = trainNetwork(cdsTrain,layers,options);
i get an error at trainnetwork script:
Error using trainNetwork (line 170)
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
Caused by:
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
I have tried quite a few similar designs for layers, by adding a few more layers in different manners, but they all display the same error, so i suspect it has something to do with the fully connected layer.
  댓글 수: 1
Arpana Singh
Arpana Singh 2022년 10월 13일
Plz help me with this error,
although i have checked my array, everyting sems fine.plz help
code
layers = [
sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numHiddenUnits)
regressionLayer
];
options = trainingOptions('adam', ...
'MaxEpochs',100, ...
'GradientThreshold',0.01, ...
'InitialLearnRate',0.0001);
net= trainNetwork(XTrain,YTrain,layers,options);
geeting the erron in line -net= trainNetwork(XTrain,YTrain,layers,options);
Error using trainNetwork
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for
that dimension.
Error in LSTM (line 27)
net= trainNetwork(XTrain,YTrain,layers,options);
Caused by:
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size
for that dimension.
>>

댓글을 달려면 로그인하십시오.

답변 (2개)

Mahesh Taparia
Mahesh Taparia 2020년 5월 12일
Hi
You are having an input of size MxN and you are directly reshaping it to a vector of length 1x1. Before the fullyConnectedLayer, there is a need to vectorized the features. To do this you can use flattenLayer before the fullyConnectedLayer. For more information, you can refer to this documentation of flattenLayer.

Nikolina Jarak
Nikolina Jarak 2021년 5월 9일
I also got this error. Can anyone help mw how to solve?
caused by: error using reshape number of elements must not change. use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by