How do I create a 1D CNN

255 ビュー (過去 30 日間)
Joshua de Jong
Joshua de Jong 2017 年 8 月 28 日
編集済み: David Willingham 2022 年 3 月 21 日
Hi there, I'm relatively new to CNNs and currently exploring the application of CNNs to 1 dimensional data sets and would greatly appreciate some assistance with an error relating to the trainNetwork function. Despite having checked and rechecked the label array repeatedly, everything appears to be in order. I'm now at the point of using trial and error. Can anyone help?
The training dataset contains 662 samples each consisting of a 1-by-800 vector. I have reshaped this to a 4D array as specified in the help documentation (see also: https://au.mathworks.com/matlabcentral/answers/331164-convolutional-1d-net )
The training label array exists in the form of a 3-by-662 array of doubles.
See below:
height = 1;
width = 800;
channels = 1;
sampleSize = 662;
CNN_TrainingData = reshape(Training_ReductWindows_G,[height, width, channels, sampleSize]);
CNN_TrainingLabels = Training_Labels_Bin_G;;
% Build the CNN layers
InputLayer = imageInputLayer([height,width,channels]); %'DataAugmentation', 'none'); %'Normalization', 'none');
c1 = convolution2dLayer([1 5], 16),'stride',[1 10]); %Filter window size = [1 5], No of filters = 16, stride = [1 10].
% We use a max pooling layer as Downsampling layer. An alternative might be
% to use an average pooling layer e.g. AveragePooling2dLayer or a reluLayer
r1 = reluLayer();
p1 = maxPooling2dLayer([1 20],'stride',[1 10]); %PoolSize = [1 20], Stride = [1 10]
f1 = fullyConnectedLayer(3); %Reduce to three output classes
s1 = softmaxLayer();
outputLayer=classificationLayer();
convnet = [InputLayer; c1; r1; p1; f1; s1; outputLayer]
opts = trainingOptions('sgdm'); %Optimise using stochastic gradient descent with momentum
convnet = trainNetwork(CNN_TrainingData, CNN_TrainingLabels, convnet, opts);
However this consistently returns the following error:
Error using trainNetwork>iAssertCategoricalResponseVector (line 598)
Y must be a vector of categorical responses.
Error in trainNetwork>iAssertValidResponseForTheNetwork (line 589)
iAssertCategoricalResponseVector(x);
Error in trainNetwork>iParseInput (line 335)
iAssertValidResponseForTheNetwork( Y, layers );
Error in trainNetwork (line 68)
[layers, opts, X, Y] = iParseInput(varargin{:});
Error in CNN (line 38)
convnet = trainNetwork(CNN_TrainingData, CNN_TrainingLabels, convnet, opts);
Can anyone point out my error?
Thank you kindly
  3 件のコメント
aybike pirol elmas
aybike pirol elmas 2020 年 5 月 31 日
Did you find the solution for your problem?
target=categorical(target_trans(1:500)'); returns the following error:
Error using categorical (line 431)
Unable to create default category names. Specify category names using the CATEGORYNAMES input argument.
but if its size is 365 and smaller, no problem.but my target data is larger than 365.

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 8 月 28 日
Try
CNN_TrainingLabels = categorical(Training_Labels_Bin_G);
  5 件のコメント
naglaa fathy
naglaa fathy 2021 年 9 月 17 日
編集済み: naglaa fathy 2021 年 9 月 17 日
trainingFeatures=[];
trainingLabel=categorical.empty();
trainingFeatures(featureCount,:) = Features;
trainingLabel(featureCount,:) = TrainingimgSets(i).Description;

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

その他の回答 (1 件)

David Willingham
David Willingham 2021 年 9 月 23 日
編集済み: David Willingham 2022 年 3 月 21 日
Hi, as of R2021b, you can create and train deep learning networks with 1-D convolution and pooling layers for sequence and time series data.
Create networks using the following layers:
The dimension that the layers convolve or pool over depends on the layer input:
  • For time series and vector sequence input (data with three dimensions corresponding to the channels, observations, and time steps, respectively), the layer convolves or pools over the time dimension.
  • For 1-D image input (data with three dimensions corresponding to the spatial pixels, channels, and observations, respectively), the layer convolves or pools over the spatial dimension.
  • For 1-D image sequence input (data with four dimensions corresponding to the spatial pixels, channels, observations, and time steps, respectively), the layer convolves or pools over the spatial dimension.
For an example showing how to train a sequence-to-label classification network using 1-D convolutions, see Sequence Classification Using 1-D Convolutions.
For an example showing how to train a sequence-to-sequence classification network using 1-D convolutions, see Sequence-to-Sequence Classification Using 1-D Convolutions.
Regards,
  2 件のコメント
David Willingham
David Willingham 2021 年 12 月 28 日
Kubo,
What is the application? 1D is good for timeseries, 2D for images, 3D for medical / LiDAR.

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

Community Treasure Hunt

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

Start Hunting!

Translated by