Error using trainNetwork. Layers argument must be an array of layers or a layer graph.
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
William Schulz
el 13 de Nov. de 2023
Comentada: William Schulz
el 30 de Dic. de 2023
Hello,
1) I'm trying to train a regression network as per below. However, when I execute: net = trainNetwork(XTrain,TTrain,layers);
I get the error message: Error using trainNetwork. Layers argument must be an array of layers or a layer graph.
2) When I execute: net = trainNetwork(XTrain,TTrain,layers,options);
I get the error message: Error using nnet.internal.cnn.trainNetwork.DLTInputParser>iParseInputArguments Too many input arguments.
Please let me know how to resolve 1 and 2 for the following code:
XTrain=InputTrainTable(:,2:end);
TTrain=InputTrainTable(:,1);
layers = [
featureInputLayer(108,"Name","featureinput","Normalization","rescale-symmetric")
tanhLayer("Name","tanh")
fullyConnectedLayer(100,"Name","fc")
regressionLayer("Name","regressionoutput")];
options = trainingOptions('sgdm');
%Question 1: Error using trainNetwork. Layers argument must be an array of layers or a layer graph.
net = trainNetwork(XTrain,TTrain,layers);
%Question 2: Error using nnet.internal.cnn.trainNetwork.DLTInputParser>iParseInputArguments. Too many input arguments.
%net = trainNetwork(XTrain,TTrain,layers,options);
0 comentarios
Respuesta aceptada
Noah Prisament
el 26 de Dic. de 2023
Hi William, the "trainNetwork" function always requires the "options" argument, so version 2 is the correct syntax.
If you are using an older version of MATLAB, the syntax that you are using was not supported and you are likely running into the same type of error as was resolved in this thread: https://www.mathworks.com/matlabcentral/answers/499762-too-many-input-arguments
If you are using a current version of MATLAB such as R2023b, then this syntax should be supported, however the responses variable must be an array instead of a table, so you must index into it using curly braces, {}, instead of parentheses, (), to get an array instead of a sub-table. I would recommend using the syntax in which you pass in a single table with both the X data and T data instead since you already have the targets in the first index (which is the assumed default). See this example in the documentation for more details: https://www.mathworks.com/help/deeplearning/ref/trainnetwork.html#mw_fcd828cc-de80-4922-8cc2-806c07deb31a
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!