필터 지우기
필터 지우기

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

조회 수: 4 (최근 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