How to Train 1d CNN on Custom dataset in matrix form in MATLAB
6 次查看(过去 30 天)
显示 更早的评论
Hi everyone, i hope you are doing well.
In my previous question : https://www.mathworks.com/matlabcentral/answers/1649260-how-to-train-cnn-on-custom-dataset-in-matrix-form
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 个评论
回答(1 个)
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
8 个评论
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 Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!