Error using trainNetwork, Invalid training data. Predictors must be a N-by-1 cell array of sequences, where N is the number of sequences. All sequences must have the same feat

13 次查看(过去 30 天)
I am trying to train a deep learning model with the training data and training label both having the same size of 409600*1. However, i keep getting the following error:
Error using trainNetwork (line 184)
Invalid training data. Predictors must be a N-by-1 cell array of sequences, where N is the number
of sequences. All sequences must have the same feature dimension and at least one time step.
Error in ML (line 71)
trainedNet = trainNetwork(y_ML(:,1)',Label_train',ly,options);
Am I doing something wrong?
clear all;close all; clc;
%% Load datasets
% load('MLsample.mat');
%Original signal
load('x_ML.mat') %label with size (409600,3)
n_samples = size(x_ML,1); %number of training samples
%received signal
load('y_ML.mat') %data with size (409600,3)
% example = matfile('x1_ML.mat')
% C = example.x1_ML;
%power allocation factor = 0.8
%% Partition Data
%Split the data into training, validation, and test sets.
%First, reserve approximately one third of the observations for the test set. Then, split the remaining data in half to create the training and validation sets.
Ds = [x_ML(:,1), y_ML(:,1)]; %Label, Data set
vector = randperm(n_samples);
% Random Split the Dataset into test and validation set
Ds_Vad = zeros(30,size(Ds,2));
Ds_Test = zeros(30,size(Ds,2));
for i = 1:60
if i <= 30
Ds_Test(i,:)= Ds(vector(i),:);
else
Ds_Vad(i-30,:) = Ds(vector(i-30),:);
end
end
Xdata_Vad = Ds_Vad(:,(2)); %data = column2 onwards
Ylabel_Vad = Ds_Vad(:,(1)); %label = column1
Xdata_Test = Ds_Test(:,(2)); %data = column2 onwards
Ylabel_Test = Ds_Test(:,(1)); %label = column1
Label_train = categorical(x_ML(:,1));
Ylabel_Vad = categorical(Ylabel_Vad);
Ylabel_Test = categorical(Ylabel_Test);
%% Network Setting
ly = [ ...
sequenceInputLayer(33)
tanhLayer
fullyConnectedLayer(10)
tanhLayer
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
maxEpochs = 2000;
miniBatchSize = 27;
%% Learning Options Setup for Fully Connected Network
options = trainingOptions('adam', ...
'MaxEpochs',maxEpochs, ...
'LearnRateDropFactor',0.01, ...
'ValidationData',{Xdata_Vad',Ylabel_Vad'}, ...
'ValidationFrequency',20, ...
'MiniBatchSize',miniBatchSize, ...
'Verbose',true, ...
'Plots','training-progress');
%% Training FC_net
trainedNet = trainNetwork(y_ML(:,1)',Label_train',ly,options);

回答(1 个)

Milan Bansal
Milan Bansal 2023-10-3
Hi,
As per my understanding you are facing an error while training a Neural Network using "trainNetowork" function while performing feature-label classification.
For feature-label classification, the input layer in the network must be a "featureInputLayer" instead of "sequenceInputLayer". Modify the input layer in the network as shown in the code below.
ly = [ ...
featureInputLayer(1) % number of features in training data
tanhLayer
fullyConnectedLayer(10)
tanhLayer
fullyConnectedLayer(2) % number of classes
softmaxLayer
classificationLayer];
Make sure that the last fully connected layer contains the argument as the number of classes in "Label_train".
Pass the trianing data in the "trainNetwork" function with columns as features and rows as observations. Modify the code as shown below.
trainedNet = trainNetwork(y_ML(:,1),Label_train,ly,options);
Similarly, modify the code for "ValidationData" in "options" as shown below.
'ValidationData',{Xdata_Vad,Ylabel_Vad}, ...
Refer to the below MathWorks documentation link to learn more about "featureInputLayer".
Refer to the Example in the below MathWorks documentation link to learn more about Train Network with Numeric Features.
Hope it helps!

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by