训练2个输入神经网络,报错‘无效的训练数据。响应必须为非空值。‘
14 views (last 30 days)
Show older comments
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)
testdata.mat中的数据。

错误使用 trainNetwork (第 183 行)
无效的训练数据。响应必须为非空值。
0 Comments
Answers (1)
T.Nikhil kumar
on 29 Sep 2023
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!
0 Comments
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!