Invalid training data. Predictors and responses must have the same number of observations.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi Everyone,
I am getting an error Invalid training data Predictors and responses must have the same number of observations in my CNN network.
My training data Tain1_In is a 4D matrix which was initially a 4050 x 400 matrix that i reshaped
My train1_Out data is 4050 x 1
The neural network doesnt run. Could you please help?
The code is attached below
%% SPLITTING MAGNITUDE DATA INTO TRAINING, TESTING AND VALIDATION
%Magnitude data
%Training data
Train_inputX1 =Magnitude_all_data; %5000 segments x 400 samples
Train_outputX1 =Modulation_Schemes ;% 5000 segments x 1
Test_X1 =ceil(0.1 *size(Magnitude_all_data,1)); % 10% is catered for testing
idx1_t= randperm(size(Magnitude_all_data,1),Test_X1);%This will generate the 10% of the random test numbers from 1 to 5000
%
% % Now I'm gonna partition the data accordingly...
testX1_input = Magnitude_all_data(idx1_t',:); %Phase test input
testX1_output = Modulation_Schemes(idx1_t); %Phase test output
Train_inputX1(idx1_t',:) = []; % assigning '[]' to matrix entries deletes them.
Train_outputX1(idx1_t',:) =[]; % Deletes the outputs that was used to test input
%
% %Now we need to repeat to find the validation data
Train1_inputX1 = Train_inputX1; %5000 segments x 400 samples
Train1_outputX1 =Train_outputX1;% 5000 segments x 1
Val_X1 =ceil(0.1 *size(Train_outputX1,1)); % 10% is catered for Validation
idx1_v= randperm(size(Train_outputX1,1),Val_X1);%This will generate the 10% of the random test numbers from 1 to 5000
%
% Now I'm gonna partition the data accordingly...
ValX1_input = Magnitude_all_data(idx1_v',:); %Mag Val input
ValX1_output =Train_outputX1(idx1_v); %Mag Val output
Train1_inputX1(idx1_v',:) = []; % assigning '[]' to matrix entries deletes them.
Train1_outputX1(idx1_v',:) =[]; % Deletes the outputs that was used to test input
%
Train1_In =reshape(num2cell(Train1_inputX1),[400,1,1,4050]);
Train1_Out =categorical(Train1_outputX1);
Val1_In =reshape(num2cell(ValX1_input),[400,1,1,450]);
Val1_Out = categorical(ValX1_output);
%% NETWORK ARCHITECTURE
layers = [imageInputLayer([400 1 1])
convolution2dLayer([102 1],3,'Stride',1)
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
convolution2dLayer([24 1],10,'Stride',1)
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
convolution2dLayer([11 1],10,'Stride',1)
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
convolution2dLayer([9 1],10,'Stride',1)
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
fullyConnectedLayer(30)
fullyConnectedLayer(10)
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
%% Specify training options.
% Note: The code below is an example. use the help for 'trainingOptions
% and change the things in this as needed. Explain all options you set and
% why. Marks are attached.
opts = trainingOptions('sgdm', ...
'MaxEpochs',40, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{Val1_In,Val1_Out},...
'ValidationPatience',Inf);
%% Train network
% Same comment as in the previous section for training options.
net = trainNetwork(Train1_In,Train1_Out,layers,opts);
1 Commento
Prince Kumar
il 23 Nov 2021
Can you please tell the size of 'Train1_In' and 'Train1_Out' after reshaping?
Risposte (0)
Vedere anche
Categorie
Scopri di più su Image Data Workflows in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!