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.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1357308/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1357308/image.png)
댓글 수: 3
답변 (1개)
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:
- https://www.matlabsolutions.com/resources/the-output-size-of-the-last-layer-does-not-match-the-response-size-.php
- https://www.reddit.com/r/matlab/comments/xvn14p/help_with_application_of_cnn_for_regression/
I hope this resolves the issue you were facing.
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!