neural network input error

3 Ansichten (letzte 30 Tage)
Junfan Zhou
Junfan Zhou am 30 Apr. 2018
Beantwortet: Tejas am 13 Nov. 2024 um 6:53
Hi friends,
I get the following error while trying to use neural network toolbox in matlab. I am new to its use, thereby any help would be crucial.
Here are my codes:
if true
% code
function NET = trainnet(net,IMGDB);
net.trainFcn = 'trainscg';
net.trainParam.lr = 0.4;
net.trainParam.epochs = 400;
net.trainParam.show = 10;
net.trainParam.goal = 1e-3;
T{1,1} = cell2mat(IMGDB(2,:));
P{1,1} = cell2mat(IMGDB(2,:));
net = train(net,P,T);
save net net
NET = net;
end
I get the following error :
if true
% code
错误使用 network/train (line 340)
Input data size does not match net.inputs{1}.size.
end
Thanks!
  1 Kommentar
Kaiwen
Kaiwen am 9 Feb. 2023
I meets the same problem.Have you solved the problem?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Tejas
Tejas am 13 Nov. 2024 um 6:53
Hello Junfan,
The error indicates a mismatch between the size of the input data and what the input layer of the neural network expects. To fix this, ensure that the input data matches the expected size of the neural network's input layer.
Check the expected input size before passing 'net' to the 'triannet' function, using the below code snippet. For more information on properties of 'net' object, refer to this documentation: https://www.mathworks.com/help/deeplearning/ref/network.html#:~:text=net.inputs,input%20i.
net.inputs{1}.size;
If the input layer size is correct, adjust the input data to match this size. Conversely, if the input layer size is not as desired, adjust the input layer to fit the input data.
Here is an example demonstrating how to modify the input layer size:
  • Generate sample data and create a sample neural network.
numFeatures = 3;
numSamples = 100;
P = rand(numFeatures, numSamples);
T = rand(1, numSamples);
hiddenLayerSize = 10;
net = feedforwardnet(hiddenLayerSize);
  • Adjust the size of the input layer accordingly.
net.inputs{1}.size = numFeatures;
NET = train(net, P, T);

Kategorien

Mehr zu Sequence and Numeric Feature Data Workflows finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by