Function to trainNetwork returns an unexpected error

1 回表示 (過去 30 日間)
Ernest Modise - Kgamane
Ernest Modise - Kgamane 2024 年 6 月 7 日
コメント済み: Matt J 2024 年 6 月 9 日
My code returns the following error for this function call - What is the fix for this?
net = trainNetwork(X_train, categorical(y_train), layers, options);
Error using trainNetwork (line 191)
Too many input arguments.
Error in LSTMGomz (line 63)
net = trainNetwork(X_train, categorical(y_train), layers, options);
Caused by:
Error using nnet.internal.cnn.trainNetwork.DLTInputParser>iParseInputArguments (line 75)
Too many input arguments.
  2 件のコメント
Matt J
Matt J 2024 年 6 月 7 日
You would have to attach a .mat file providing inputs X_train, categorical(y_train), layers, options for us to run with.
Ernest Modise - Kgamane
Ernest Modise - Kgamane 2024 年 6 月 7 日
編集済み: Ernest Modise - Kgamane 2024 年 6 月 7 日

サインインしてコメントする。

採用された回答

Matt J
Matt J 2024 年 6 月 8 日
編集済み: Matt J 2024 年 6 月 8 日
Your X_train and y_train data were in some weird format that trainNetwork cannot recognize. Try this instead,
Xdata = num2cell(readmatrix('LSTMdataIn.xlsx')',1)';
N=200;
train_ratio=0.8;
split_index=round(train_ratio*N);
inputSize = height(Xdata{1}); % Number of features in the input data
numClasses = height(Xdata)/N; % Number of categories
Xdata=reshape(Xdata,N,numClasses);
ydata=repmat(1:numClasses,N,1);
X_train=Xdata(1:split_index,:);
y_train=ydata(1:split_index,:);
X_test=Xdata(split_index+1:end,:);
y_test=ydata(1:split_index+1:end,:);
layers = [
sequenceInputLayer(inputSize)
lstmLayer(100, 'OutputMode', 'last')
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer
];
options = trainingOptions('adam', 'MaxEpochs', 100);
net = trainNetwork(X_train(:), categorical(y_train(:)), layers, options);
Training on single CPU. |========================================================================================| | Epoch | Iteration | Time Elapsed | Mini-batch | Mini-batch | Base Learning | | | | (hh:mm:ss) | Accuracy | Loss | Rate | |========================================================================================| | 1 | 1 | 00:00:00 | 20.31% | 1.6082 | 0.0010 | | 9 | 50 | 00:00:00 | 79.69% | 0.4997 | 0.0010 | | 17 | 100 | 00:00:00 | 82.81% | 0.2851 | 0.0010 | | 25 | 150 | 00:00:01 | 76.56% | 0.3004 | 0.0010 | | 34 | 200 | 00:00:01 | 79.69% | 0.2844 | 0.0010 | | 42 | 250 | 00:00:01 | 82.81% | 0.2591 | 0.0010 | | 50 | 300 | 00:00:01 | 76.56% | 0.2918 | 0.0010 | | 59 | 350 | 00:00:02 | 79.69% | 0.2794 | 0.0010 | | 67 | 400 | 00:00:02 | 82.81% | 0.2565 | 0.0010 | | 75 | 450 | 00:00:02 | 76.56% | 0.2902 | 0.0010 | | 84 | 500 | 00:00:03 | 79.69% | 0.2782 | 0.0010 | | 92 | 550 | 00:00:03 | 82.81% | 0.2557 | 0.0010 | | 100 | 600 | 00:00:03 | 76.56% | 0.2895 | 0.0010 | |========================================================================================| Training finished: Max epochs completed.
  3 件のコメント
Ernest Modise - Kgamane
Ernest Modise - Kgamane 2024 年 6 月 9 日
Hi Mat, You have created an interesting data structure for this purpose. I would like to spend time on learning how to configure the data structure. Please send me tops to look at.
Matt J
Matt J 2024 年 6 月 9 日
It's just a cell array of numeric data. You had tables nested inside cells, I think.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by