训练2个输入神经网络​,报错‘无效的训练数​据。响应必须为非空值​。‘

17 次查看(过去 30 天)
InTron@BJUT
InTron@BJUT 2022-6-8
load('nn.mat')
filedatastore = fileDatastore( 'testdata.mat' , 'ReadFcn' ,@load);
options = trainingOptions('adam', ...
'MaxEpochs',10, ...
'MiniBatchSize', 5, ...
'InitialLearnRate', 0.01, ...
'GradientThreshold', 1, ...
'ExecutionEnvironment',"auto",...
'plots','training-progress', ...
'Verbose',false);
Newnet = trainNetwork(filedatastore,lgraph_1,options)
Error using trainNetwork
Invalid training data. For a network with 2 inputs and 1 output, the datastore read function must return a cell array with 3 columns, but it returns an cell array with 1 columns.
testdata.mat中的数据。
错误使用 trainNetwork (第 183 行)
无效的训练数据。响应必须为非空值。

回答(1 个)

T.Nikhil kumar
T.Nikhil kumar 2023-9-29
Hello,
As per my understanding, the read function of your datastore is returning a cell array with 1 column when it is expected to return a cell array with 3 columns and consequently you are facing an “Invalid Training Data” error.
The error occurred in the “C” cell array in the “testdata.mat” file. The second input to the network i.e. the second column of this “C” cell array contains the features as “double” type objects of [1X40] size. These should have been of the size [40X1] since the “featureInputLayer” of the defined network in “lgraph_1” has 40 features. You can rectify this by transposing each object in this cell array. Follow the below code snippet.
%Accessing the second column of "C" variable
CCol2=C(:,2);
%Creating a new cellarray and initialising it with the first transposed [40X1] array
NewCol2={(CCol2{1,1})'};
%Looping through the size of cell array and transposing every matrix
for i=2:900
NewCol2=[CWithNewCol2 ;{(CCol2{i,1})'}];
end
%Update the second column of "C" variable
C=[C(:,1) NewCol2 C(:,3)];
For training neural networks with multiple inputs, we would require the ”features” argument of the “trainNetwork” function to be of “combinedDatastore” or “transformedDatastore” type only. Therefore, you should first use the “transform” function to convert the “fileDatastore” object to “transformedDatastore” type. You can define a custom transformation function “rearrangeData” to be used to transform the “fileDatastore” to ensure the “read(datastore)” returns [MX3] cell array.
trainingDatastore = transform(filedatastore,@rearrangeData);
function out = rearrangeData(ds)
out = ds.C;
end
You can refer to the following documentation to understand more about the “trainNetwork” function and the types of “features” arguments allowed.
You can refer to the following question where a similar issue is answered.
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!