Error Using trainNetwork (line 170). Too many input arguments.

Where did i go wrong? Please help me with the code.
I have a table of 500x31 (features as columns =30 and class lable column 31 ). Feature values are in rows for 5 class (100 rows for each class).
dataset sample is shown below. when i run the code i am getting error
"Error using trainNetwork (line 170)
Too many input arguments.
Error in calling1 (line 30)
net = trainNetwork(dataTrain,YTrain,layers_1,options);
Caused by:
Error using trainNetwork>iParseInputArguments (line 326)
Too many input arguments."
%Spliting the data set into 80:20
cvp=cvpartition(coif2level3.class,'holdout',0.2);
dataTrain=coif2level3(training(cvp),:);
dataValidation=coif2level3(test(cvp),:);
XTrain=dataTrain(:,1:30);
YTrain=dataTrain.class;
YValidation=dataValidation.class;
%XTrain size 400x30
%YTrain size 400X1
%workspace
% Defining LSTM Architecture
numFeatures = 30;
numHiddenUnits = 100;
numClasses = 5;
layers_1= [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
miniBatchSize = 27;
maxEpochs = 100;
options = trainingOptions('adam', ...
'ExecutionEnvironment','cpu', ...
'MaxEpochs', ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',2, ...
'Shuffle','every-epoch', ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(dataTrain,YTrain,layers_1,options);

 Akzeptierte Antwort

Christopher McCausland
Christopher McCausland am 11 Feb. 2021
Bearbeitet: Christopher McCausland am 11 Feb. 2021

0 Stimmen

"Too many input arguments" is a sign that the function expects fewer input arguments. In this case your input arguments appear to be=> dataTrain,YTrain,layers_1,options.
Are only the arguments included in your function call? I think you may have included an extra one, or more.
[Returned_Argument] = myfunc(dataTrain,YTrain,layers_1,options);

6 Kommentare

I didnot understand you .. the function trainNetwork takes in 4 input arguments. (dataTrain,YTrain,layers_1,options)
net = trainNetwork(dataTrain,YTrain,layers_1,options);
Hi Syed,
I did some further digging, I suggest you have a look at the expected inputs for the trainNetwork function, here is the help file link. A similar question has been asked before here, as you can see they have passed unexpected variable types and recevive a similar error. The use of categorical inputs rather than numerical is not supported.
syed
syed am 17 Feb. 2021
Bearbeitet: syed am 17 Feb. 2021
Dear Christopher
The link was very helpful. I developed the code but face one error with featureInputLayer
%LSTM code for classification with featureset
%reading the feature file as table
filename="coif3_level1.xlsx";
data=readtable(filename);
%converting the class lable into categorical
labelname="class";
data=convertvars(data,labelname,'categorical');
%spliting the data set randomly 80:20 ratio.
data=splitvars(data);
head(data)
classNames=categories(data{:,labelname});
numObservations=size(data,1);
numObservationsTrain=floor(0.80*numObservations);
numObservationsTest=numObservations - numObservationsTrain;
%Create an array of random indices corresponding to the observations and partition it using the partition sizes
idx = randperm(numObservations);
idxTrain = idx(1:numObservationsTrain);
idxTest = idx(numObservationsTrain+1:end);
%Partition the table of data into training, validation, and testing partitions using the indices.
dataTrain=data(idxTrain,:);
dataTest=data(idxTest,:);
%Define a network with a feature input layer and specify the number of features. Also, configure the input layer to normalize the data using Z-score normalization.
numFeatures=size(data,2) - 1;
numClasses=numel(classNames);
layers = [
featureInputLayer(numFeatures,'Normalization', 'zscore')
fullyConnectedLayer(50)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
miniBatchSize = 16;
options = trainingOptions('adam', ...
'MiniBatchSize',miniBatchSize, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false);
%Train the network using the architecture defined by layers, the training data, and the training options.
net = trainNetwork(dataTrain,layers,options);
%Predict the labels of the test data using the trained network and calculate the accuracy. The accuracy is the proportion of the labels that the network predicts correctly.
YPred = classify(net,dataTest,'MiniBatchSize',miniBatchSize);
YTest = dataTest{:,labelname};
%Prefromance Overall Accuracy
Overall_Accuracy = sum(YPred == YTest)/numel(YTest);
figure
confusionchart(YTest,YPred,'ColumnSummary','column-normalized',...
'RowSummary','row-normalized','Title','Confusion Chart for LSTM');
when I run the code i get an error as " Unrecognized function or variable 'featureInputLayer'. ". I am using matlab 2020a
introduced in R2020b
thank you
I meet same problem. I have checked the arguments . It indeed don't add extra one.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Deep Learning Toolbox finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by