How to Train 1d CNN on Custom dataset in matrix form in MATLAB

6 ビュー (過去 30 日間)
Med Future
Med Future 2022 年 2 月 17 日
コメント済み: yanqi liu 2022 年 2 月 18 日
Hi everyone, i hope you are doing well.
yanqi liu answer the question with 2D CNN, But i wanted to train 1D CNN
i have the following dataset myFile.txt includes 102x5,in which first 4 coloums are the Number of Observation and the last column are the Discrete labels/Classes for the dataset. I want to train 1D-CNN on this dataset
sz = size(dataset);
dataset = dataset(randperm(sz(1)),:);
traindata=dataset(:,1:4);
trainlabel=categorical(dataset(:,5));
classes = unique(trainlabel)
numClasses = numel(unique(trainlabel))
PD = 0.80 ;
Ptrain = []; Ttrain = [];
Ptest = []; Ttest = [];
for i = 1 : length(classes)
indi = find(trainlabel==classes(i));
indi = indi(randperm(length(indi)));
indj = round(length(indi)*PD);
Ptrain = [Ptrain; traindata(indi(1:indj),:)]; Ttrain = [Ttrain; trainlabel(indi(1:indj),:)];
Ptest = [Ptest; traindata(indi(1+indj:end),:)]; Ttest = [Ttest; trainlabel(indi(1+indj:end),:)];
end
Ptrain=(reshape(Ptrain', [4,1,1,size(Ptrain,1)]));
Ptest=(reshape(Ptest', [4,1,1,size(Ptest,1)]));
layers = [imageInputLayer([4 1 1])
convolution2dLayer([3 1],3,'Stride',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
dropoutLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
options = trainingOptions('adam', ...
'MaxEpochs',3000, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{Ptest,Ttest},...
'ExecutionEnvironment', 'cpu', ...
'ValidationPatience',Inf);
net = trainNetwork(Ptrain,Ttrain,layers,options);
  3 件のコメント
Med Future
Med Future 2022 年 2 月 17 日
編集済み: Med Future 2022 年 2 月 17 日
@yanqi liu where i can change in convolution2dLayer to set dimension 1

サインインしてコメントする。

回答 (1 件)

yanqi liu
yanqi liu 2022 年 2 月 17 日
編集済み: yanqi liu 2022 年 2 月 17 日
yes,sir,if 2021b has convolution1dLayer,so we can make the cnn as follows,then we can try train it
layers = [sequenceInputLayer(4)
convolution1dLayer(3,32,Padding="causal")
reluLayer
globalMaxPooling1dLayer
dropoutLayer
fullyConnectedLayer(5)
softmaxLayer
classificationLayer];
layers
layers =
8×1 Layer array with layers: 1 '' Sequence Input Sequence input with 4 dimensions 2 '' Convolution 32 3 convolutions with stride 1 and padding 'causal' 3 '' ReLU ReLU 4 '' 1-D Global Max Pooling 1-D global max pooling 5 '' Dropout 50% dropout 6 '' Fully Connected 5 fully connected layer 7 '' Softmax softmax 8 '' Classification Output crossentropyex
  8 件のコメント
Med Future
Med Future 2022 年 2 月 17 日
@yanqi liu this is not training curve
yanqi liu
yanqi liu 2022 年 2 月 18 日
yes,sir,here on web,we can not see the plot curve,so we get the train status info and plot it
this picture is train acc curve by stats info structure

サインインしてコメントする。

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by