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 Comments

I am working on similar problem. I have time histories for two signals A(t) and B(t). Each containing 10000 time entries (1X10000 vector). I have 100 training examples
A1(t), A2(t), ......, A100(t)
B1(t), B2(t), ......, B100(t)
How do I setup "TrainingVector" (before reshape command)
In order to use reshape command on "TrainingVector" Is below info correct? sampleSize = 100; channels = 2; Height = 1; Width = 10000;
------------------------------------------------
One more thing, I am performing regression instead of classification. Problem consists of One output signal containing (10000 elements) So how do I set up target matrix ------100 X 10000 matrix?
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
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.

Sign in to comment.

 Accepted Answer

Try
CNN_TrainingLabels = categorical(Training_Labels_Bin_G);

5 Comments

Joshua de Jong
Joshua de Jong on 28 Aug 2017
Edited: Joshua de Jong on 28 Aug 2017
Thanks Walter, The categorical() function appears to help, however it reduces the number of classes from 3 to 2. Despite having three mutually exclusive classes and examples for each. I suspect this is because categorical() is reducing the available classes to a 0 or 1 instead of 001, 010, 100?
I understood from the help doc'n, that the labels could be an array of doubles...?
If I change the labels from 001, 010 and 100 to '0', '1', and '2'. It appears to work?
>> categorical([001 010 100])
ans =
1×3 categorical array
1 10 100
No obvious problem ?
How to solve this error?
Error using categorical/subsasgn (line 84)
Cell contents assignment to a non-cell array object.
Error in Trainingcode (line 35)
trainingLabel{featureCount} = TrainingimgSets(i).Description;
Code:
trainingFeatures(featureCount,:) = Features;
trainingLabel{featureCount} = TrainingimgSets(i).Description;
featureCount = featureCount + 1;
personIndex{i} = TrainingimgSets(i).Description;
%% CNN Classifier
layers = [
fullyConnectedLayer(7)
softmaxLayer
classificationLayer];
options = trainingOptions('sgdm','MaxEpochs',20,'InitialLearnRate',1e-4,'Verbose',false);
trainingLabel = categorical(trainingLabel);
net = trainNetwork(trainingFeatures,trainingLabel,layers,options);
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 on 17 Sep 2021
Edited: naglaa fathy on 17 Sep 2021
trainingFeatures=[];
trainingLabel=categorical.empty();
trainingFeatures(featureCount,:) = Features;
trainingLabel(featureCount,:) = TrainingimgSets(i).Description;

Sign in to comment.

More Answers (1)

David Willingham
David Willingham on 23 Sep 2021
Edited: David Willingham on 21 Mar 2022
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 Comments

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
Kubo,
What is the application? 1D is good for timeseries, 2D for images, 3D for medical / LiDAR.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!