Invalid training data. The output size ([1 1 1]) of the last layer does not match the response size ([1 1 1773])

2 views (last 30 days)
Hi,
I am trying for solar power prediction using cnn. It has 6 input features and 1 output. I have tried the following code. But i got the error during training as "Invalid training data. The output size ([1 1 1]) of the last layer does not match the response size ([1 1 1773])".
%% load data
% XTraining & YTraining
input_data = xlsread("forecast_data.xlsx", 1);
len_train = floor(0.8*length(input_data));
XTrain = input_data(1:len_train,1:6);
YTrain = input_data(1:len_train,7);
XTrainReshaped = reshape(XTrain, [len_train 6 1 1]);
YTrainReshaped = reshape(YTrain, [len_train 1 1 1]);
% create convolutional network
Conv1 = convolution2dLayer([1 1], 10, 'NumChannels',1, 'Stride',[1,1], 'Padding',[1 1 1 1], WeightLearnRateFactor=1, ...
BiasLearnRateFactor=1, name='Conv1')
Conv1.Weights = sqrt(2/(9*10)) * randn(1,1,1,10,'single');
Conv1.Bias = randn(1, 1, 10, 'single');
% construct layer
input_data2 = [imageInputLayer([6 1 1])]
layers = [input_data2; convolution2dLayer(1,32); reluLayer; ...
convolution2dLayer(1,64); reluLayer; convolution2dLayer(1,128); reluLayer; dropoutLayer(0.2); ...
fullyConnectedLayer(1); softmaxLayer; regressionLayer];
% training option
opts = trainingOptions('adam', 'MaxEpochs',10, 'InitialLearnRate',0.0001, ...
'GradientThreshold',0.1)
net = trainNetwork(XTrainReshaped', YTrainReshaped', layers, opts);
Please help me to rectify this error. Also, if possible suggest me a code to run the forecasting.
Thank you in advance.
  3 Comments
sastra university
sastra university on 16 Apr 2023
Hi sir,
Thank you for the reply.
numel(unique(YTrainReshaped)) is 1773. Here in this reply, i have attached a file with 200 sample data. Please help me to rectify.
Thank you.

Sign in to comment.

Answers (1)

Manikanta Aditya
Manikanta Aditya on 28 Apr 2023
Hi,
As per my understanding, you are getting an error “Invalid training data. The output size ([1 1 1]) of the last layer does not match the response size ([1 1 1773])".
After a quick google search, I found few related references to your error:
I hope this resolves the issue you were facing.

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!