CNN: How to create label vector acceptable by trainNetwork

5 ビュー (過去 30 日間)
Parichada Trairat
Parichada Trairat 2021 年 8 月 15 日
回答済み: Anshika Chaurasia 2021 年 9 月 17 日
I'm trying to create cnn for load forecasting. I try to create lebel vector for training but it didn't work.
I have 3 types of data with 1920 samples fo each for training set (1920x3 double) and 3 types of data with 768 samples fo each for testing set (768x3 double). I reshaped train data to 4D array.
this is my code for this work.
%% Reshaped input
Train_dataset = reshape(Train_data, [1 1920 1 3]);
% Creat the labels
label = (1:3,:);
Train_Labels = categorical(label);
%% Layers
layers = [ ...
imageInputLayer([1 1920 1])
convolution2dLayer(1,20)
reluLayer
maxPooling2dLayer(1,'Stride',1)
fullyConnectedLayer(1)
softmaxLayer
classificationLayer];
%% Train Options
train_options = trainingOptions('sgdm');
%% Train network
net = trainNetwork(Train_dataset, Train_Labels, layers, train_options);
%% Test network
Pred = classify(net, Test_data)'
What is the train lebel should look like? or somewhere was wrong?
the error frequently shows 'Number of observations in X and Y disagree.'

採用された回答

Anshika Chaurasia
Anshika Chaurasia 2021 年 9 月 17 日
Hi,
The error is appearing because the number of observations in "Train_dataset" and "Train_Labels" are different.
So, if "Train_dataset" is 1920x3 then "Train_Labels" should be 1920x1.
One more thing, following line can throw error as indexing can be applied on an array:
label = (1:3,:);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by