필터 지우기
필터 지우기

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

조회 수: 12 (최근 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 CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by