필터 지우기
필터 지우기

1D CNN for sequence-to-label classification, model input errors

조회 수: 12 (최근 30일)
Ohiomueti Uantioje
Ohiomueti Uantioje 2023년 11월 25일
편집: Debraj Maji 2023년 11월 28일
I created a 1D CNN to classify numerical sequences into 5 classes. I cannot get the correct input formatting to train the model
data = num2cell(data, 2); % sequence input format
label = categorical(label); % response input format
for i=1:length(data)
data{i} = data{i}';
end
[idxTrain,idxTest] = trainingPartitions(numel(data), [0.9 0.1]);
dataTrain = data(idxTrain);
labelTrain = label(idxTrain);
dataTest = data(idxTest);
labelTest = label(idxTest);
options = trainingOptions("adam",...
'InitialLearnRate',1e-3,...
'LearnRateDropFactor',0.1,...
'LearnRateDropPeriod',20,...
'MaxEpochs',60,...
'MiniBatchSize',36,...
'LearnRateSchedule','piecewise', ...
'Shuffle','every-epoch', ...
'Verbose',false, ...
'Plots','training-progress');
[net,model_performance] = trainNetwork(dataTrain, labelTrain, CNN, options);
the input format are as follows:
sequence input (cell array)
label input (categorical scalar)- classes include ["N","L","R","A","V"]

채택된 답변

Debraj Maji
Debraj Maji 2023년 11월 28일
편집: Debraj Maji 2023년 11월 28일
I understand that you are trying to train a 1D CNN Network.
The response variable in the 'trainNet' function should be a cell array of categorical row vectors(every cell is a categorical row vector) and not a simple categorical row vector as the input consists of multiple observations. In your case 'labelTrain' should not be a 900*1 categorical row vector but a 1x900 cell where each individual cell is a categorical row vector.
One of the possible ways of modifying the above code to accomodate the change would be to use a cell array where each element is a categorical row vector. I have attached the correct code below for your reference:
clear;
load test\CNN.mat;
data = num2cell(data,2); % sequence input format
label = categorical(label); % response input format
for i=1:length(data)
data{i} = data{i}';
end
label1 = {};
for i=1:length(label)
label1{i} = categorical(label(i))';
end
[idxTrain,idxTest] = trainingPartitions(numel(data), [0.9 0.1]);
dataTrain = data(idxTrain);
labelTrain = label1(idxTrain);
dataTest = data(idxTest);
labelTest = label1(idxTest);
options = trainingOptions("adam",...
'InitialLearnRate',1e-3,...
'LearnRateDropFactor',0.1,...
'LearnRateDropPeriod',20,...
'MaxEpochs',60,...
'MiniBatchSize',36,...
'LearnRateSchedule','piecewise', ...
'Shuffle','every-epoch', ...
'Verbose',false, ...
'Plots','training-progress');
[net,model_performance] = trainNetwork(dataTrain, labelTrain, CNN, options);
After running the above code with the attached data the Accuracy and loss curves obtained are attached below:
I hope this resolves your query.
With regards,
Debraj.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by