trainNetwork not running because categorical row vector not found even though it's there

4 views (last 30 days)
I'm running a deep learning script over a signal dataset using a sequence-to-label architecture I put together in the Deep Learning Network designer. The input has two channels and I'm attempting to output into 41 separate classes using 1D-CNN/LSTM. I defined the train and test data as such:
idx = splitlabels(labels,[0.8,0.1,0.1])
trainidx = idx{1}
validx = idx{2}
testidx = idx{3}
traindata = sigdata(trainidx)
trainlabels = labels(trainidx)
valdata = sigdata(validx)
vallabels = labels(validx)
testdata = sigdata(testidx)
testlabels = labels(testidx)
The training options are defined as:
opts = trainingOptions("adam", ...
"Plots","training-progress", ...
"ValidationData",{valdata vallabels}, ...
"InitialLearnRate",0.0001, ...
"MaxEpochs",15, ...
"Shuffle","every-epoch", ...
"ValidationFrequency",20, ...
"MiniBatchSize",32)
and the network architecture looks like:
12×1 Layer array with layers:
1 'sequence' Sequence Input Sequence input with 2 dimensions
2 'conv1d' 1-D Convolution 8 3 convolutions with stride 1 and padding 'same'
3 'batchnorm' Batch Normalization Batch normalization
4 'relu' ReLU ReLU
5 'maxpool1d' 1-D Max Pooling Max pooling with pool size 2, stride 1, and padding 'same'
6 'conv1d_1' 1-D Convolution 8 3 convolutions with stride 1 and padding 'same'
7 'batchnorm_1' Batch Normalization Batch normalization
8 'relu_1' ReLU ReLU
9 'lstm' LSTM LSTM with 128 hidden units
10 'fc' Fully Connected 41 fully connected layer
11 'softmax' Softmax softmax
12 'classoutput' Classification Output crossentropyex
I'd prefer not to use global pooling layers, because that would lead to a very low classification accuracy. Using all of these inputs, I attempt to train the network:
damagenet = trainNetwork(traindata,trainlabels,layers_1,opts)
However, doing this leads to the following compilation error:
Error using trainNetwork
Invalid training data for sequence-to-sequence classification network. For multiple observations, the responses
must be a cell array of categorical row vectors. For a single observation, the responses can be also a single
categorical row vector.
This doesn't make any sense to me, as I'm not trying to run a sequence-to-sequence; I'm trying sequence-to-label. Hence the size-41 fully-connected layer. Furthermore, I am using a cell array of categorical row vectors. In Workspace, my labels variable is listed as a 4141x1 categorical. And again, I don't get this error when I try it with a global pooling layer after the last relu layer. I just get a classification with really low accuracy.
What should I do to my network, training data, or options for the code to run without error? Any help or advice is appreciated.
Thanks!
  4 Comments
Said El-Hawwat
Said El-Hawwat on 15 Jan 2024
I'm sorry but it would be nice if I could just email it to you personally. Even when I take a subset it still tells me that the filesize is too big to attach

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 12 Jan 2024
Perhaps this example will help?
I'm not able to duplicate the error, but using the data from the example, the following ran without error.
idx = splitlabels(labels,[0.8,0.1,0.1])
trainidx = idx{1}
validx = idx{2}
testidx = idx{3}
traindata = data(trainidx)
trainlabels = labels(trainidx)
valdata = data(validx)
vallabels = labels(validx)
testdata = data(testidx)
testlabels = labels(testidx)
% layers generated by Deep Network Designer
layers_1 = [
sequenceInputLayer(numChannels,"Name","input")
convolution1dLayer(8,3,"Name","conv1d","Padding","same")
batchNormalizationLayer("Name","batchnorm")
reluLayer("Name","relu")
maxPooling1dLayer(2,"Name","maxpool1d","Padding","same")
convolution1dLayer(8,3,"Name","conv1d_1","Padding","same")
batchNormalizationLayer("Name","batchnorm_1")
reluLayer("Name","relu_1")
lstmLayer(128,"Name","lstm","OutputMode","last")
fullyConnectedLayer(numClasses,"Name","fc")
softmaxLayer("Name","softmax")
classificationLayer("Name","classification")];
opts = trainingOptions("adam", ...
"Plots","training-progress", ...
"ValidationData",{valdata vallabels}, ...
"InitialLearnRate",0.0001, ...
"MaxEpochs",15, ...
"Shuffle","every-epoch", ...
"ValidationFrequency",20, ...
"MiniBatchSize",32);
damagenet = trainNetwork(traindata,trainlabels,layers_1,opts)
  1 Comment
Said El-Hawwat
Said El-Hawwat on 15 Jan 2024
Thanks for the help; this allowed me to get around the categorical dataset issue.
Unfortunately my training accuracy is still too low though.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!