How do I create a 1D CNN

93 ビュー (過去 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 件のコメント
João M. Lopes
João M. Lopes 2020 年 3 月 17 日
Hello
Did you find the solution for your problem?
I'm having the same issue here: how should we rearrange our signals to create the 4D-array? The channels are our number of features? Or should we create a matrix of 2-by-10000-by-1-by-100, in which width is our signals' length and height is our number of features?
Moreover, I have another question: did you have problems with the fully connected layer regarding the output size? In my case, my target is a matrix 1-by-7600. I'm always having a size problem... it says that it is needed a huge array and matlab would become unresponsive. Did you get the same error?
Thanks in advance
JML
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 件のコメント
Image Analyst
Image Analyst 2020 年 3 月 23 日
Like it says, trainingLabel is not a cell array. How did you define it earlier? Did you do something like this
trainingLabel = cell(1,1);
or was it produced by a function that returns a cell array? I'm guessing not.
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 件のコメント
Kuno Bruswachtl
Kuno Bruswachtl 2021 年 12 月 27 日
hi,
I am also pretty new to cnns and need one for my thesis. Should i used your described version for an input 6570x1 and a wanted output of 10x10x5. or should i rather upscale the my 1D input so i can reach a 3D output. Thank you so much for your help.
regards
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