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

8 次查看(过去 30 天)
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 个评论
sastra university
sastra university 2023-4-16
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.

请先登录,再进行评论。

回答(1 个)

Manikanta Aditya
Manikanta Aditya 2023-4-28
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.

类别

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

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by