neural network input error

3 次查看(过去 30 天)
Junfan Zhou
Junfan Zhou 2018-4-30
回答: Tejas 2024-11-13,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 个)

Tejas
Tejas 2024-11-13,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);

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by