MATLAB Answers

Why do I get the error "The output layer expects responses with the same sequence length and feature dimension 2" when using a data store in my network training?

6 views (last 30 days)
I train a neuronal network using a combined data store. 
I created two separate fileDatastore objects, one for the samples and one for the labels.
Then, I used the ReadFcn to prepare the samples and to prepare the labels.
Then, I defined the RNN layers and training options and attempt to train the network.
This results in the following error:
 
Error using trainNetwork (line 183)
Unexpected response size: The output layer expects responses with the same sequence length and feature dimension 2.
When separately defining XTrain and YTrain from the same Datastores, I do not get this error, but this requires the training data to be in memory which I want to avoid.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 20 Jul 2021
When you create a categorical array from the numeric label, this array will think there is only one class because it hasn't been seen or been told otherwise. However, this categorical array needs to be aware it is storing elements that can belong to one of two classes.
The following documentation page will contain the necessary information about creating categorical arrays: https://www.mathworks.com/help/matlab/ref/categorical.html#d123e142165
Doing this should enable the network to train.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!